note 105978 added to regexp.reference.recursive

From: Date: Thu, 29 Sep 2011 14:15:03 +0000
Subject: note 105978 added to regexp.reference.recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-183526@lists.php.net to get a copy of this message
Recursive pattern match does not work with start of subject ^ option 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 ) 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); ---- Server IP: 212.124.37.9 Probable Submitter: 217.91.31.53 ---- Manual Page -- http://www.php.net/manual/en/regexp.reference.recursive.php Edit -- https://master.php.net/note/edit/105978 Del: integrated -- https://master.php.net/note/delete/105978/integrated Del: useless -- https://master.php.net/note/delete/105978/useless Del: bad code -- https://master.php.net/note/delete/105978/bad+code Del: spam -- https://master.php.net/note/delete/105978/spam Del: non-english -- https://master.php.net/note/delete/105978/non-english Del: in docs -- https://master.php.net/note/delete/105978/in+docs Del: other reasons-- https://master.php.net/note/delete/105978 Reject -- https://master.php.net/note/reject/105978 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183526) next »