aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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: 1075
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: 17257
    
    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: 1075
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: 1075
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: 17257
    
    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: 1075
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
 
 
subject: Invalid RegEx on @Pattern