You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by Gabrio Verratti <ga...@brokat.com> on 2001/08/03 21:58:01 UTC

difference between contains and matches

I'm using your ORO v1.1.0a API and I wanted to know what the difference
between contains() and matches() is.  The latest javadoc (@ Jakarta)
suggests that the two are different in certain situations, but I'm not
entirely clear about this.

This is what the javadoc says:

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.


Any help would be invaluable.

Thanks in advance,

Gabrio Verratti