Re: Perl 5's "non-greedy" matching can be TOO greedy!

[email protected] (Bart Lateur) Sun, 17 Dec 2000 02:59:17 +0100
Newsgroups perl.perl6.language.regex
Organization MediaMind
Message-ID <[email protected]>
On Fri, 15 Dec 2000 13:42:44 -0700, Kevin Walker wrote:

>Deven seems to be advocating thinking about regular expressions 
>without worrying too much about the implementation, even at a fairly 
>abstract level.

Here's a counter example:

	/aaaabbbbccccdddddbbbbcdddd/

Shouldn't a non-greedy matcher /b.*?d/, according to the OP's rules,
match "bcd", the second matching string? That is shorter than the first
match. Oh, you want the first match. Well: same thing.

It is similar in nature to that question in comp.lang.perl.misc the
other day: why doesn't greediness force /a|ab/ to preferably match "ab"?
Because it doesn't. Try from left to right, first match wins. A dead
simple rule.

If Perl's greediness/nongreediness doesn't work for you, rely on
something else, to get what you want.

-- 
	Bart.