Bug #79028 [Csd->Nab]: Several same-name subpatterns in distinct piped alternatives should be allowed
| From: | cmb@php.net | Date: | Wed, 25 Dec 2019 10:05:09 +0000 |
| Subject: | Bug #79028 [Csd->Nab]: Several same-name subpatterns in distinct piped alternatives should be allowed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224528@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79028&edit=1
ID: 79028
Updated by: cmb@php.net
Reported by: php4fan at gmail dot com
Summary: Several same-name subpatterns in distinct piped
alternatives should be allowed
-Status: Closed
+Status: Not a bug
Type: Bug
Package: *Regular Expressions
PHP Version: 7.2.26
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2019-12-24 17:36:50] php4fan at gmail dot com
Ok, I see, "(?J)" modifies the behavior to accomplish what I asked for.
So, not a bug.
Sorry about the noise.
------------------------------------------------------------------------
[2019-12-24 17:18:05] php4fan at gmail dot com
Description:
------------
see below test script and expected and observed behavior below.
Maybe this an issue at the level of regular expressions specifications. As I only use them in PHP, I
don't know, so I report it here. Also, it's so evidently flawed that maybe PHP could
implement them correctly anyway while waiting for the specs to be fixed; not sure about that.
Test script:
---------------
<?php
$content = <<<'HERE'
First match: foo::"XYZ"
Second match: bar--<XYZ>
HERE;
$content=preg_replace_callback('#foo::"(?<sub>[^"]*)"|bar--<(?<sub>[^>]*)>#',
'testReplace', $content);
function testReplace($match) {
print_r($match);
return 'XXX';
}
Expected result:
----------------
Array
(
[0] => foo::"XYZ"
[sub] => XYZ
[1] => XYZ
)
Array
(
[0] => bar--<XYZ>
[1] =>
[sub] => XYZ
[2] => XYZ
)
Actual result:
--------------
Warning: preg_replace_callback(): Compilation failed: two named subpatterns have the same name
Because the subgroups with the same name appear on two sides of a "|", there should be no
conflict. At most one of the piped patterns (i.e. either side of the "|") can match, they
are mutually exclusive, so there is no ambiguity possible and it should be a problem that a subgroup
appear in both of them with the same name, as it can only be assigned once anyway.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79028&edit=1