This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Spring and the fly likes Invalid RegEx on @Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Invalid RegEx on @Pattern" Watch "Invalid RegEx on @Pattern" New topic
Author

Invalid RegEx on @Pattern

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1073
In Eclipse, I get an invalid escape sequence from the pattern below to validate an email address box.



The error is referring to the "\." below.

However, I can find this same regular expression in several places on the Internet (and in Spring books).

What's wrong here?

Thanks.

mike
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Does it need to be escapes, because in there it thinks the \ is an escape? so Use "\\"

Or is it the other way around where you put it in there as an escape and it doesn't need it?

Just guessing here.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1073
Mark Spritzler wrote:Does it need to be escapes, because in there it thinks the \ is an escape? so Use "\\"

Or is it the other way around where you put it in there as an escape and it doesn't need it?

Just guessing here.

Mark


Hi Mark,

As I understand it, since "." is a RegEx operator, to use it as a regular period (.), as in validating the "." before the domain, you have to escape it with a "\".

If you used two \ marks, then you're escaping the escape character itself.

Thanks,

mike

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1073
Mike London wrote:
Mark Spritzler wrote:Does it need to be escapes, because in there it thinks the \ is an escape? so Use "\\"

Or is it the other way around where you put it in there as an escape and it doesn't need it?

Just guessing here.

Mark


Hi Mark,

As I understand it, since "." is a RegEx operator, to use it as a regular period (.), as in validating the "." before the domain, you have to escape it with a "\".

If you used two \ marks, then you're escaping the escape character itself.

This email validation code came right out of "Spring 3 in Action".

Thanks,

mike

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Mike London wrote:
Mark Spritzler wrote:Does it need to be escapes, because in there it thinks the \ is an escape? so Use "\\"

Or is it the other way around where you put it in there as an escape and it doesn't need it?

Just guessing here.

Mark


Hi Mark,

As I understand it, since "." is a RegEx operator, to use it as a regular period (.), as in validating the "." before the domain, you have to escape it with a "\".

If you used two \ marks, then you're escaping the escape character itself.

Thanks,

mike



OK, Just checking. and I hate Regex because I don't understand it and I am awful at it. ;)

Mark
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1073
LOL

Well, now I'm wondering if it's a bug somewhere.

I'm following up with the IDE company as well.

Thanks Mark.

mike
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Invalid RegEx on @Pattern