#43104 [Opn]: preg_* not capturing regex optional last parenthesis value if empty
| From: | felipe@php.net | Date: | Fri, 23 Nov 2007 01:32:21 +0000 |
| Subject: | #43104 [Opn]: preg_* not capturing regex optional last parenthesis value if empty | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-119974@lists.php.net to get a copy of this message | ||
ID: 43104
Updated by: felipe@php.net
Reported By: ch+php at 1111-internet dot com
Status: Open
Bug Type: PCRE related
Operating System: n/a
PHP Version: 4.4.7
New Comment:
This is expected for flag different of default. (PREG_PATTERN_ORDER)
Previous Comments:
------------------------------------------------------------------------
[2007-10-24 23:53:26] ch+php at 1111-internet dot com
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 this bug report at http://bugs.php.net/?id=43104&edit=1