|more useful options|
Re^3: A Perl vs. Java fight brewsby emazep (Priest)
|on Jul 25, 2006 at 10:11 UTC||Need Help??|
Though regex support in Java was introduced several years ago (but not that many: JDK 1.4 AFAIK, 2002 circa, if we mean the java.util.regex package), it still doesn't offer advanced things such as match-time code evaluation, match-time pattern interpolation and conditional interpolation.
So, for example, with a Java regex you can't build a recursive pattern (to check for instance if the parentheses in a text are balanced), while in Perl you can ;-)
It can also be interesting to see how more verbose Java regexes are compared to Perl regexes.
Here is a simple Perl example:
and here is its Java counterpart:
Really, the above 2 last lines could be substituted by the following somewhat shorter code:
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.)