#20856 [NEW]: preg_match backreference fails

From: Date: Fri, 06 Dec 2002 12:35:52 +0000
Subject: #20856 [NEW]: preg_match backreference fails
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-26841@lists.php.net to get a copy of this message
From: earth_php@erowid.org Operating system: freebsd 4.7 stable PHP version: 4.2.2 PHP Bug Type: PCRE related Bug description: preg_match backreference fails Perhaps I am misunderstanding something about the differences between perl regex and php perl regex, but this looks like a bug to me. The back references are behaving strangely.. I think the following code demonstrates it fairly well. Removing the back reference from the preg_match code results in a successful match as expected. The following code fails in php 4.2.2: $string = "blah/blah/other/stuff/here.html"; if (preg_match("/^\/?([^\/]+\/)(\1)/",$string,$matches) ) { print "found match: $matches[1] <BR>\n"; } else { print "failed to match.. <BR>\n"; } in perl 5.x, it works fine: my $string = "blah/blah/other/stuff/here.html"; if ($string =~ /^\/?([^\/]+\/)(\1)/) { print "found match: $1 <BR>\n"; } else { print "failed to match.. <BR>\n"; } configure command: './configure' '--with-apxs=/usr/local/sbin/apxs' '--with-config-file-path=/usr/local/etc' '--enable-versioning' '--with-regex=system' '--without-gd' '--without-mysql' '--with-gd=/usr/local' '--enable-gd-native-ttf' '--with-freetype-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-zlib' '--with-bz2=/usr' '--with-mcrypt=/usr/local' '--with-mhash=/usr/local' '--with-mysql=/usr/local' '--with-openssl=/usr' '--with-expat-dir=/usr/local' '--with-xmlrpc' '--enable-xslt' '--with-xslt-sablot' '--enable-ftp' '--with-curl=/usr/local' '--with-gettext=/usr/local' '--with-iconv=/usr/local' '--enable-trans-sid' '--prefix=/usr/local' 'i386-portbld-freebsd4.6' Thanks for looking at this, earth earth_php@erowid.org -- Edit bug report at http://bugs.php.net/?id=20856&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=20856&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=20856&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=20856&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=20856&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=20856&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=20856&r=support Expected behavior: http://bugs.php.net/fix.php?id=20856&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=20856&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=20856&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=20856&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20856&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=20856&r=dst IIS Stability: http://bugs.php.net/fix.php?id=20856&r=isapi

« previous php.bugs (#26841) next »