note 22607 added to function.preg-replace

From: Date: Mon, 24 Jun 2002 19:46:55 +0000
Subject: note 22607 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-32161@lists.php.net to get a copy of this message
lonestarn8, Instead of using the limit argument, which may have other side effects, try the Perl-ish solution of adding a "?" after the matched expression. This makes the match work non-greedily. For example, in a project I'm working on, this fails to match anything: preg_replace("/(\\includegraphics[.|\s]*)$oldExt/", "\\1$newExt", $text); but this works fine for every occurrence: preg_replace("/(\\includegraphics[.|\s]*)?$oldExt/", "\\1$newExt", $text); -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+22607 http://master.php.net/manage/user-notes.php?action=delete+22607 http://master.php.net/manage/user-notes.php?action=reject+22607

« previous php.notes (#32161) next »