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 ;-)
Update
It can also be interesting to see how more verbose Java regexes are compared to Perl regexes.
Here is a simple Perl example:
my $pat = qr/a+b/;
my $res = "aaab" =~ $pat;
and here is its Java counterpart:
import java.util.regex.*;
Pattern pat = Pattern.compile("a+b");
Matcher mat = pat.matcher("aaab");
boolean res = mat.matches();
Really, the above 2 last lines could be substituted by the following somewhat shorter code:
boolean res = pat.matcher("aaab").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.)
Ciao, Emanuele.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.