|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-09-29 09:45 UTC] 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
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
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);