note 77822 added to function.preg-replace
| From: | SantoshPatnaik at osu1 dot php dot net | Date: | Fri, 14 Sep 2007 06:11:18 +0000 |
| Subject: | note 77822 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130489@lists.php.net to get a copy of this message | ||
Once a match is identified, the regular expression engine appears to set aside the matching segment
of the target string. A second segment that you expect to match may therefore end up not getting
matched:
// Expect 'pa pa pa pa' but get 'pa ma pa ma'
echo preg_replace('
(^|\s)ma(\s|$)', '$1pa$2', 'ma ma ma
ma');
Here the issue can be solved by using a 'lookahead':
// Expect and get 'pa pa pa pa'
echo preg_replace('(^|\s)ma(?=\s|$)', '$1pa', 'ma ma ma
ma');
----
Server IP: 69.147.83.197
Probable Submitter: 59.161.122.8
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/77822
Del: integrated -- https://master.php.net/note/delete/77822/integrated
Del: useless -- https://master.php.net/note/delete/77822/useless
Del: bad code -- https://master.php.net/note/delete/77822/bad+code
Del: spam -- https://master.php.net/note/delete/77822/spam
Del: non-english -- https://master.php.net/note/delete/77822/non-english
Del: in docs -- https://master.php.net/note/delete/77822/in+docs
Del: other reasons-- https://master.php.net/note/delete/77822
Reject -- https://master.php.net/note/reject/77822
Search -- https://master.php.net/manage/user-notes.php