in reply to Re: greedy search
in thread greedy search

There's often no difference between minimalistic and greedy matching, because of anchoring:

/a*b/
is the same as
/a*?b/

When there is a difference, minimalistic is usually just a shortcut for negative matching:

'<a href="">text</a>' =~ /<((?!>).)*>/
can be written as
'<a href="">text</a>' =~ /<[^>]*>/
can be written as
'<a href="">text</a>' =~ /<.*?>/

'{begin} foo {cmd} bar {end} {begin} baz {end}' =~ /{begin}((?!{end}).)*{end}/
can be written as
'{begin} foo {cmd} bar {end} {begin} baz {end}' =~ /{begin}.*?{end}/</code>

While minimalistic matching can replace negative matching, it's not the same. However, I can't think of case where minimalistic matching is required. Since it's optional, many regexp engine do not provide it, making greedy the default (and only) option. (As an aside, most regexp engine usually don't provide (?!...) either, so they have a limitation.)