Re: Pattern Regular Expressions: Consecutive ORs not handled corr ectl y

"Daniel F. Savarese" <[email protected]> Tue, 03 May 2005 14:08:05 -0400
Newsgroups gmane.comp.jakarta.oro.user
Message-ID <[email protected]>
In message <A3E375FA108EF94496269A5A96AFCAC102E2187F@mailwest-e6>, Kayiti Devan
andam writes:
>Please do find attached the test case for it. (testRegEx.java which can be
>compiled with putting "jakarta-oro-2.0.8.jar" in the classpath.)
>With both the 2.0.5 and 2.0.8 versions I am finding the following results:
>
>For the stringPattern -->> \d{3}|\d{3}(.)\d{2}
>	123 -> Passed
>	123.46 Failed (which shouldn't fail)

That's a different pattern than the one you originally posted.  Since
I now can see from your test case that you are using matches(), I can
tell you the problem is exactly the foo|foot scenario I mentioned.  It
is explained in the documentation for Perl5Matcher.matches.  There is
no bug.  You should use either
  \d{3}(.)\d{2}|\d{3} (although I suspect you mean \d{3}\.\d{2}|\d{3})
or
 ^(?:\d{3}|\d{3}(.)\d{2})$
or
 \d{3}(?:(.)\d{2})?

The simplest thing to do when using matches() if you either don't
understand the foo|foot scenario and how Perl expressions match with
respect to alternations or if you have a complicated expression, is
to simply stick the expression inside of ^(?:)$, turning foo|foot
into ^(?:foo|foot)$

daniel