You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by Tarun Ramakrishna Elankath <et...@blr.cognizant.com> on 2004/02/04 13:20:14 UTC

behaviour of Perl5Matcher.matches doesn't seem to properly take care of alternatives.

Hi,

I have a zip code. It's length can be 5 digits, 9 digits or 12 digits.
My Perl5Pattern pattern (say ptn) is: \d{5}|\d{9}|\d{12}

I have input string, say zip5, zip9 and zip12 that are strings of digits 
of length 5, 9 and 12 respectively.

When I use Perl5Matcher.matches(), zip5 passed, but zip9 and zip 12 
fails. I tried the online demo and it failed there too.

If I re-arrange the pattern to be \d{9}|\d{5}|\d{12}, then zip9 passed 
but zip5 and zip12 fail.

For some reason, it only seems to consider the first alternative. Is 
this the expected functional behaviour ?

So, I am reduced to specifying my pattern as a cumbersome: 				 
^\d{5}$|^\d{9}$|^\d{12}$
and using Perl5Matcher.contains. This works fine.

All help/information much appreciated,
Thanks,
Tarun