Re: Re[2]: Pattern Regular Expressions: Consecutive ORs not handled corr ectl y

"Daniel F. Savarese" <[email protected]> Wed, 04 May 2005 13:02:42 -0400
Newsgroups gmane.comp.jakarta.oro.user
Message-ID <[email protected]>
I wrote:
>The result will not be bar, it's bart.  If you want foo|foot to match
>foot you've either got to rewrite it as foot|foo or as ^(?:foo|foot)$.
>For example,
>
>  echo foot | perl -pi -e 's/^(?:foo|foot)$/bar/g'

I should clarify that this is only if you want the entire input to
match.  If you want to match maximally within some arbitrary input
(e.g., "football"), you have to restructure and use foot|foo.  I
think the source of the misunderstanding is simply that Perl just
doesn't do things how one would expect.  Overall longest matching is
what most of us would expect.  Regular expressions are essentially
microprograms and they need to be optimized to do what you want
with respect to the pattern matching rules of the particular
system being used.  Perl expressions require more tweaking than
most.

daniel