RE: Bad character class exception on pattern that works for JDK's Pattern class
"Reuben Sivan" <[email protected]> Thu, 12 Oct 2006 22:22:59 -0400
| Newsgroups | gmane.comp.jakarta.regexp.user |
|---|---|
| Message-ID | <00e801c6ee6e$82273a60$165aa8c0@Olympus> |
Jim,
Apparently the workaround I suggested the other day wasn't the best one, as
it allowed you to compile but then failed at match-time.
This new fix seems to work OK in both java.util.regex and org.apache.regexp:
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][\-\w]*[0-9a-zA-Z]\.)+[a-zA-Z
]{2,9})$
My guess is that [-\w] and [\w-] are either not well defined or mishandled
by regexp; in either case escaping the hyphen takes care of (or avoids) the
problem.
Interestingly regexp did accept [-.\w] ...
Reuben
-----Original Message-----
From: Jim K [mailto:[email protected]]
Sent: Thursday, October 12, 2006 6:12 PM
To: [email protected]
Subject: Re: Bad character class exception on pattern that works for JDK's
Pattern class
I ran through a bunch of unit tests to validate that the RE compiled pattern
operated the same as when compiled with either ORO's Perl5Compiler or Java's
Pattern. I found that in one instance it did not:
username@[email protected]
I'd expect this pattern to fail the match and it does for ORO and Java. But
it
passes when run through Apache regexp. The pattern as amended is:
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][\w-]*[0-9a-zA-Z]\.)+[a-zA-Z]
{2,9})$