Re: Another regexp conundrum

Ronald J Kimball <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
On Tue, Jun 01, 2004 at 05:22:01PM -0400, [email protected] wrote:
> 
>    /(anything)*/ can always match a zero length substring at the beginning of
>    the string, and as soon as the regex engine finds a match, it stops.  The
>    (?!) forces the regex engine to backtrack through all possible matches.
> 
> I can see how that would be the case if the modifier were *?, but with
> plain * I expect the engine to match greedily, and not stop at the
> first match.

Emphasis: *at the beginning of the string*.

Without the (?!), your regex matches zero occurences of $re at the
beginning of the string.

The regex engine always finds the longest, *leftmost* match.  (Where
"longest" really means "with the least backtracking".)

Ronald
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.