Re: preg_match_all but no preg_replace_all?

From: Date: Tue, 10 Aug 2004 18:24:54 +0000
Subject: Re: preg_match_all but no preg_replace_all?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-193348@lists.php.net to get a copy of this message
* Peter Brodersen <php@ter.dk>: > 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:matthew@garden.org | http://vermontbotanical.org

« previous php.general (#193348) next »