In message <[EMAIL PROTECTED]>, Tarun Ramakrishna Elankath wri tes: >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. ... >So, I am reduced to specifying my pattern as a cumbersome: > >^\d{5}$|^\d{9}$|^\d{12}$ >and using Perl5Matcher.contains. This works fine.
Everything's okay. You did the right thing. From the javadocs: Note: matches() is not the same as sticking a ^ in front of your expression and a $ at the end of your expression in Perl5 and using the =~ operator, even though in many cases it will be equivalent. matches() literally looks for an exact match according to the rules of Perl5 expression matching. Therefore, if you have a pattern foo|foot and are matching the input foot it will not produce an exact match. But foot|foo will produce an exact match for either foot or foo. Remember, Perl5 regular expressions do not match the longest possible match. From the perlre manpage: Alternatives are tried from left to right, so the first alternative found for which the entire expression matches, is the one that is chosen. This means that alternatives are not necessarily greedy. For example: when matching foo|foot against "barefoot", only the "foo" part will match, as that is the first alternative tried, and it successfully matches the target string. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]