Bug #63218 [Opn->Nab]: Recursion and greedy
| From: | rasmus@php.net | Date: | Thu, 04 Oct 2012 13:58:35 +0000 |
| Subject: | Bug #63218 [Opn->Nab]: Recursion and greedy | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173891@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63218&edit=1
ID: 63218
Updated by: rasmus@php.net
Reported by: jille at hexon dot cx
Summary: Recursion and greedy
-Status: Open
+Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: n/a
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
Any regex-related bug report should include the results from pcretest so we can
see whether it is something that is specific to PHP or whether it is simply how
the PCRE library works. eg.
re> /{[A-Z]+(\|param:[^|}]*(?R)?[^|}]*)*}/
data> A{X|param:{Y}}B
0: {X|param:{Y}
1: |param:{Y
So as far as I can see this one has nothing to do with PHP. If you still feel it
is a bug, you should file it against PCRE at http://www.pcre.org/
and get back
to us with the results. As far as I can tell from a quick look at that regex, it
is doing exactly what I would expect.
Previous Comments:
------------------------------------------------------------------------
[2012-10-04 11:39:33] jille at hexon dot cx
5.3.10 has the same problem.
------------------------------------------------------------------------
[2012-10-04 11:38:16] jille at hexon dot cx
Description:
------------
See test-script. When I make the recursive-backreference (?R) optional (with ?) it doesn't
match $str to its full extent.
Test script:
---------------
<?php
$str = "A{X|param:{Y}}B";
$reWanted = '/{[A-Z]+(\|param:[^|}]*(?R)?[^|}]*)*}/';
var_dump(preg_match($reWanted, $str, $m), $m);
$reWorking = '/{[A-Z]+(\|param:[^|}]*(?R)[^|}]*)*}/';
var_dump(preg_match($reWorking, $str, $m), $m);
$reWorking2 = '/{[A-Z]+(\|param:([^|}]*(?R)[^|}]*|[^|}]*))*}/';
var_dump(preg_match($reWorking2, $str, $m), $m);
?>
Expected result:
----------------
For all three cases:
int(1)
array(3) {
[0]=>
string(13) "{X|param:{Y}}"
[1]=>
string(10) "|param:{Y}"
[2]=>
string(3) "{Y}"
}
Actual result:
--------------
Using $reWanted gives this instead of the expected result. Note the missing }
int(1)
array(2) {
[0]=>
string(12) "{X|param:{Y}"
[1]=>
string(9) "|param:{Y"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63218&edit=1