note 85278 added to function.preg-replace
| From: | tasser at ne8 dot in | Date: | Sat, 23 Aug 2008 14:24:19 +0000 |
| Subject: | note 85278 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143766@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 59.162.86.33
Probable Submitter: 122.167.32.146
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/85278
Del: integrated -- https://master.php.net/note/delete/85278/integrated
Del: useless -- https://master.php.net/note/delete/85278/useless
Del: bad code -- https://master.php.net/note/delete/85278/bad+code
Del: spam -- https://master.php.net/note/delete/85278/spam
Del: non-english -- https://master.php.net/note/delete/85278/non-english
Del: in docs -- https://master.php.net/note/delete/85278/in+docs
Del: other reasons-- https://master.php.net/note/delete/85278
Reject -- https://master.php.net/note/reject/85278
Search -- https://master.php.net/manage/user-notes.php