My understanding is that Java\'s implementation of regular expressions is based on Perl\'s. However, in the following example, if I execute the same regex with the same str
Additionally, the Perl regex syntax is NOT the Java Regex Syntax.
It doesn't apply necessarily in this case, but this is a more answer to your more general question.
Java has a regular expression syntax known as "PCRE", ie: Perl Compatible.
This name is however grossly misleading, because there is very very little about it which is really Perl compatible.
For instance, Perl regular expressions permit executing code in the expression itself, and lots of other advanced operators, and some syntax are different in Perl as they are in other languages ( ie: many languages use \>
and \<
as word boundary markers, but Perl just uses '\b' )
Spend a few minutes to read some of the PerlRe Documentation and you'll discover lots of awesome tricks that Perl's regular expression engine can do that nothing else seems to do.
The Java matches
method is testing whether the regex matches the entire String
. To test whether a regex can be found anywhere in a string, create a Matcher and use its find method.