Edit report at https://bugs.php.net/bug.php?id=55811&edit=1
ID: 55811 User updated by: sajidm at gmx dot net Reported by: sajidm at gmx dot net Summary: preg_match recursive does not work with start of subject ^ option Status: Open 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: 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); Previous Comments: ------------------------------------------------------------------------ [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