From: ch+php at 1111-internet dot com Operating system: n/a PHP version: 4.4.7 PHP Bug Type: PCRE related Bug description: preg_* not capturing regex optional last parenthesis value if empty
Description: ------------ The code and results attached show two examples of preg_* demonstrating how an optional parenthesis match at the end of a regular expression is not being captured if the optional condition is not matched. I think this is a bug, because if the optional parenthesis is not the last one in the regex, the empty value IS captured - which suggests that it should not be omitted just because it happens to be the last one. Reproduce code: --------------- preg_match_all("/(1)(23)?/", "12314123", $match, PREG_SET_ORDER); print_r($match); print_r(preg_split("/(1)(23)?/", "12314123", -1, PREG_SPLIT_DELIM_CAPTURE)); Expected result: ---------------- Array ( [0] => Array ( [0] => 123 [1] => 1 [2] => 23 ) [1] => Array ( [0] => 1 [1] => 1 [2] => ) [2] => Array ( [0] => 123 [1] => 1 [2] => 23 ) ) Array ( [0] => [1] => 1 [2] => 23 [3] => [4] => 1 [5] => [6] => 4 [7] => 1 [8] => 23 [9] => ) Actual result: -------------- Array ( [0] => Array ( [0] => 123 [1] => 1 [2] => 23 ) [1] => Array ( [0] => 1 [1] => 1 ) [2] => Array ( [0] => 123 [1] => 1 [2] => 23 ) ) Array ( [0] => [1] => 1 [2] => 23 [3] => [4] => 1 [5] => 4 [6] => 1 [7] => 23 [8] => ) -- Edit bug report at http://bugs.php.net/?id=43104&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43104&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43104&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43104&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43104&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43104&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43104&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43104&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43104&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43104&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43104&r=support Expected behavior: http://bugs.php.net/fix.php?id=43104&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43104&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43104&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43104&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43104&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43104&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43104&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43104&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43104&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43104&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43104&r=mysqlcfg