* Peter Brodersen <[EMAIL PROTECTED]>:
> On 10 Aug 2004 16:53:59 -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.

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.

> "greedy" is the term of whether or not a range of matches should be
> expanded to as long as possible, e.g.:

Good point; I was a bit hasty in my terminology. I should have said
'*global* by default'.

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED]         | http://vermontbotanical.org

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

Reply via email to