note 54816 added to reference.pcre.pattern.syntax

From: Date: Fri, 15 Jul 2005 19:22:29 +0000
Subject: note 54816 added to reference.pcre.pattern.syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-92036@lists.php.net to get a copy of this message
Some simple assertions so you only match inside (or outside) an html tag: <?php $string1 = "<b><span class=\"match1\">match2</span><span class=\"match3\">match4</span></b>match5"; $string2 = preg_replace( "/match(?![^<]*?>)/", "replacement", $string1 ); // Matches outside the html tag $string3 = preg_replace( "/match(?=[^<]*?>)/", "replacement", $string1 ); // Matches inside the html tag echo "1: " . str_replace(array("<",">"), array("&lt;","&gt;"), $string1) . "<br>\n"; echo "2: " . str_replace(array("<",">"), array("&lt;","&gt;"), $string2) . "<br>\n"; echo "3: " . str_replace(array("<",">"), array("&lt;","&gt;"), $string3) . "<br>\n"; ?> This outputs: 1: <b><span class="match1">match2</span><span class="match3">match4</span></b>match5 2: <b><span class="match1">replacement2</span><span class="match3">replacement4</span></b>replacement5 3: <b><span class="replacement1">match2</span><span class="replacement3">match4</span></b>match5 ---- Manual Page -- http://www.php.net/manual/en/reference.pcre.pattern.syntax.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54816 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54816&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54816&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92036) next »