php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20856 preg_match backreference fails
Submitted: 2002-12-06 06:35 UTC Modified: 2002-12-06 09:11 UTC
From: earth_php at erowid dot org Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.2.2 OS: freebsd 4.7 stable
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: earth_php at erowid dot org
New email:
PHP Version: OS:

 

 [2002-12-06 06:35 UTC] earth_php at erowid dot 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-06 09:11 UTC] msopacua@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC