#20856 [Opn->Bgs]: preg_match backreference fails
| From: | msopacua@php.net | Date: | Fri, 06 Dec 2002 15:11:46 +0000 |
| Subject: | #20856 [Opn->Bgs]: preg_match backreference fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-26846@lists.php.net to get a copy of this message | ||
ID: 20856
Updated by: msopacua@php.net
Reported By: earth_php@erowid.org
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: freebsd 4.7 stable
PHP Version: 4.2.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Since you're using double quotes, the \1 is the ascii character \1. You
need to provide \\1 to get the backreference.
Previous Comments:
------------------------------------------------------------------------
[2002-12-06 06:35:52] earth_php@erowid.org
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 this bug report at http://bugs.php.net/?id=20856&edit=1