|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-10-04 11:38 UTC] 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"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
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.