Bug in look-behind assertions in PCRE patterns ?

From: Date: Wed, 23 Mar 2005 16:38:42 +0000
Subject: Bug in look-behind assertions in PCRE patterns ?
Groups: php.general 
Request: Send a blank email to php-general+get-211390@lists.php.net to get a copy of this message
Dear All Is this a bug ? I'm using look-behind assertions within preg_match() to ignore certain combinations of patterns. E.g. from ref. manual is: (?<!foo)bar matches "bar" but only if it's not preceded by "foo". Here's my test script: ---------------- $line = '$res = foobar("ddd", "dfdf");'; if (preg_match("/(?<!foo)(bar)/", $line, $matches)) {
        echo "Should NOT match foobar, but found: ".$matches[1];
} $line = '$res = $bar("ddd", "dfdf");'; if (preg_match("/(?<!\$)(bar)/", $line, $matches)) {
        echo "Should NOT match \$bar, but found: ".$matches[1];
} ---------------- In the first preg_match() is correctly ignores the foobar function name. However the second preg_match() does NOT ignore the $bar as I expected. I converted this to Perl and it correctly ignores both! Is this a bug, or am I missing something ? using PHP-4.3.10 + apache 1.3.33 + fc 1 Many thanks Ian -- Ian Thurlbeck http://www.stams.strath.ac.uk/ Statistics and Modelling Science, University of Strathclyde Livingstone Tower, 26 Richmond Street, Glasgow, UK, G1 1XH Tel: +44 (0)141 548 3667 Fax: +44 (0)141 552 2079

« previous php.general (#211390) next »