From: php at sameprecision dot org Operating system: irrelevant PHP version: 5.2.5 PHP Bug Type: PCRE related Bug description: preg_match_all makes extra matches on empty alternatives
Description: ------------ Performing a global match with empty alternative in subpattern followed by $ alternative in subpattern results in "extra" match. In the example below, I believe that preg_match_all should match the second 'a' in the first subpattern, match the end of subject assertion in the second subpattern and flag the global search as over. I've tried this with php5.2.5/pcre7.3 on linux. Reproduce code: --------------- $regex = '/(a|)(,|$)/'; echo preg_match_all($regex, 'a,', $m1, PREG_SET_ORDER)."\n"; print_r($m1); echo preg_match_all($regex, 'a,a' ,$m2, PREG_SET_ORDER)."\n"; print_r($m2); Expected result: ---------------- 2 Array ( [0] => Array ( [0] => a, [1] => a [2] => , ) [1] => Array ( [0] => [1] => [2] => ) ) 2 Array ( [0] => Array ( [0] => a, [1] => a [2] => , ) [1] => Array ( [0] => a [1] => a [2] => ) ) Actual result: -------------- 2 Array ( [0] => Array ( [0] => a, [1] => a [2] => , ) [1] => Array ( [0] => [1] => [2] => ) ) 3 Array ( [0] => Array ( [0] => a, [1] => a [2] => , ) [1] => Array ( [0] => a [1] => a [2] => ) [2] => Array ( [0] => [1] => [2] => ) ) -- Edit bug report at http://bugs.php.net/?id=44463&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44463&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44463&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44463&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44463&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44463&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44463&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44463&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44463&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44463&r=support Expected behavior: http://bugs.php.net/fix.php?id=44463&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44463&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44463&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44463&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44463&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44463&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44463&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44463&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44463&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44463&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44463&r=mysqlcfg