Edit report at https://bugs.php.net/bug.php?id=63218&edit=1
ID: 63218 Updated by: ras...@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