Re: preg_match_all but no preg_replace_all?

From: Date: Tue, 10 Aug 2004 19:31:14 +0000
Subject: Re: preg_match_all but no preg_replace_all?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-193373@lists.php.net to get a copy of this message
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

« previous php.general (#193373) next »