Edit report at https://bugs.php.net/bug.php?id=63218&edit=1
ID: 63218 User updated by: jille at hexon dot cx Reported by: jille at hexon dot cx Summary: Recursion and greedy Status: Open Type: Bug Package: PCRE related Operating System: n/a PHP Version: 5.4.7 Block user comment: N Private report: N New Comment: 5.3.10 has the same problem. Previous Comments: ------------------------------------------------------------------------ [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