This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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


Win a copy of Android Security Essentials Live Lessons this week in the Android 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: 1043
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: 17249
    
    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: 1043
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: 1043
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: 17249
    
    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: 1043
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid RegEx on @Pattern
 
Similar Threads
regexp on email address
Validating domain name with struts validator
First hand at RegEx
Quick Javascript & RegEx quuestion
Email Validation