in reply to Re^2: A Perl vs. Java fight brews
in thread A Perl vs. Java fight brews
and here is its Java counterpart:my $pat = qr/a+b/; my $res = "aaab" =~ $pat;
Really, the above 2 last lines could be substituted by the following somewhat shorter code:import java.util.regex.*; Pattern pat = Pattern.compile("a+b"); Matcher mat = pat.matcher("aaab"); boolean res = mat.matches();
but if you don't explicitly instantiate a Matcher object, you can't have several things such as match, prematch, postmatch etc. which Perl gives you for free (through the various predefined variables $&, $`, $' etc.)boolean res = pat.matcher("aaab").matches();
|
|---|