note 85278 deleted from function.preg-replace by felipe
| From: | felipe@php.net | Date: | Sun, 24 Aug 2008 04:27:48 +0000 |
| Subject: | note 85278 deleted from function.preg-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143782@lists.php.net to get a copy of this message | ||
Note Submitter: tasser at ne8 dot in
----
preg_replace is non-greedy by default, and the behaviour of ? on the pattern is to make it greedy
contrary to what i read on PCRE docs.
If the aforementioned behavious is already on the docs, point me to the correct link.
$str ="asdfd adsfd aaaadasd";
$str = preg_replace("/(a)(.*)(d)/","a($2)d",$str);
a(sdfd adsfd aaaadas)d
$str = preg_replace("/(a)(.*)?(d)/U","a($2)d",$str);
a(s)dfd a()dsfd a(aaa)da(s)d
which is what i wanted.