On 10 Aug 2004 18:24:54 -0000, 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)
>
>Umm, not in perl. Perl will only replace the *first* match, unless the g
>switch is passed to the s/// construct (e.g., s/a/b/g will replace all
>occurrences of a with b; s/a/b/ will only replace the first). In other
>words, perl's substitution operator is not *global* by default; PHP's
>preg_replace is, however.

I can see what I wrote could be misunderstood. I mentioned that it is
greedy per default, which also is the case for ereg_* and perl.

>And regexps are only *greedy* when using wildcards for quantifiers, not by
>default (e.g., s/a/b/ only replaces a single occurence of a; s/a*/b/
>will replace an 0 or more occurences of a followed by anything with b --
>aaaab -> bb, as does ab -> bb). In other words, regexps are not *greedy*
>by default, either.

Err, the *quantifiers* are still greedy per default (which can be
negated), but of course it requires that quantifiers actually are used
:)

So, the "greedy"-terminology simply relates to quantifiers.

-- 
- Peter Brodersen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to