php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46184 a problem with internal vars
Submitted: 2008-09-26 15:38 UTC Modified: 2008-09-28 10:11 UTC
From: vasilkov80 at mail dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.6 OS: linux mandriva 2007
Private report: No CVE-ID: None
 [2008-09-26 15:38 UTC] vasilkov80 at mail dot ru
Description:
------------
a problem with internal vars?

/\"([^\"]+\.jpg)\"/ - the pattern works fine...
/([\"\'])([^\\1]+\.jpg)\\1/ - a bit more complex pattern doesn't work as expected!

Reproduce code:
---------------
if( preg_match("%([\"\']{1})([^\\1]+\.jpg)\\1%", '.. "bla bla "image.jpg" .. " bla bla', $matches) )
	print_r($matches);

Expected result:
----------------
Array
(
    [0] => "image.jpg"
    [1] => image.jpg
)

Actual result:
--------------
Array
(
    [0] => "bla bla "image.jpg"
    [1] => "
    [2] => bla bla "image.jpg
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-26 15:44 UTC] vasilkov80 at mail dot ru
sorry, expected result:

Array
(
    [0] => "image.jpg"
    [1] => "
    [2] => image.jpg
)
 [2008-09-28 10:11 UTC] nlopess@php.net
your regex is wrong.

quote from the PCRE manual:
"Outside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a back reference to a capturing sub-pattern  earlier  (that is, to its left) in the pattern, provided there have been that many previous capturing left parentheses."

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC