On Tue, 10 Aug 2004 14:50:26 -0400, in php.general you wrote:
>>>Yes. preg_replace is greedy by default.
>> Err, global, that is (although it's also greedy per default, but then
>> again, that's also the case for ereg-functions and perl)
><snip>
>Regular expressions in Perl are not greedy by default. You have to
>specify the 'g' for it to be greedy.
You might want to read the last part of my post, about the common
mix-up of the meaning of "greedy" and "global" - Q.E.D. :)
1. "greedy" is a term used to specify the behaviour of *quantifiers*
(like {x,y}, +, ?, *)
2. The g-flag does not stand for "greedy", but "global". This
behaviour has nothing to do with quantifiers, and using the g-flag
doesn't change whether or not a quantifier is greedy. The U-flag does
that, though.
3. From perldoc perlre:
By default, a quantified subpattern is "greedy", that is,
it will match as many times as possible (given a particuÂ
lar starting location) while still allowing the rest of
the pattern to match. If you want it to match the minimum
number of times possible, follow the quantifier with a
"?". Note that the meanings don't change, just the
"greediness":
There really is a common mix-up between these two words, as you have
just proved :)
(I'm pretty sure that we all agree of the actual behaviour of /g,
though - this is only an issue regarding words)
--
- Peter Brodersen
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php