Edit report at https://bugs.php.net/bug.php?id=55811&edit=1
ID: 55811 Updated by: [email protected] Reported by: sajidm at gmx dot net Summary: preg_match recursive does not work with start of subject ^ option -Status: Open +Status: Bogus Type: Bug Package: *Regular Expressions Operating System: openSuse 11.1(Linux 2.6.27) PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2011-09-30 05:05:11] [email protected] so as I said above, this is not a bug, I am going to mark this as bogus, thanks for you time to write these to us. ------------------------------------------------------------------------ [2011-09-29 15:21:55] [email protected] IMO the (?R) means match the regular pattern itself, in your case it like (^pattern(^pattern**** , so I think the result was worked `as expect`. ------------------------------------------------------------------------ [2011-09-29 14:03:09] sajidm at gmx dot net Workaround: use wrapper function for preg_match function preg_match_ex($pattern, $str, &$m, $recursive = false) { if($recursive) { $pattern = "$pattern(\s*,\s*$pattern)*"; } return preg_match("!^($pattern)!i", $str, $m); } Usage: preg_match_ex("\d+", "22222, 33333, 44444 ,55555,abcd,defg,4537, 6537, 8774", true); ------------------------------------------------------------------------ [2011-09-29 09:45:38] sajidm at gmx dot net Description: ------------ when i try php -r 'preg_match("!((\d+)(\s*,\s*(?R))*)$!","22222, 33333, 44444 ,55555 , abcd,defg,4537, 6537, 8774", $m);echo print_r($m,1);' Array ( [0] => 4537, 6537, 8774 [1] => 4537, 6537, 8774 [2] => 4537 [3] => , 6537, 8774 ) Similarly it should work with start of subject ^ option but it does not work. It works fine without start of subject ^ option Test script: --------------- php -r 'preg_match("!^((\d+)(\s*,\s*(?R))*)!","22222, 33333, 44444 ,55555 , abcd,defg,4537, 6537, 8774", $m);echo print_r($m,1);' Expected result: ---------------- Array ( [0] => 22222, 33333, 44444 ,55555 [1] => 22222, 33333, 44444 ,55555 [2] => 22222 [3] => , 33333, 44444 ,55555 ) Actual result: -------------- Array ( [0] => 22222 [1] => 22222 [2] => 22222 ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55811&edit=1
