|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79028 Several same-name subpatterns in distinct piped alternatives should be allowed
Submitted: 2019-12-24 17:18 UTC Modified: 2019-12-25 10:05 UTC
From: php4fan at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 7.2.26 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php4fan at gmail dot com
New email:
PHP Version: OS:


 [2019-12-24 17:18 UTC] php4fan at gmail dot com
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:

$content = <<<'HERE'

First match: foo::"XYZ"
Second match: bar--<XYZ>


$content=preg_replace_callback('#foo::"(?<sub>[^"]*)"|bar--<(?<sub>[^>]*)>#', 'testReplace', $content);

function testReplace($match) {
    return 'XXX';

Expected result:
    [0] => foo::"XYZ"
    [sub] => XYZ
    [1] => XYZ
    [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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-24 17:36 UTC] php4fan at gmail dot com
-Status: Open +Status: Closed
 [2019-12-24 17:36 UTC] 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-25 10:05 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 18:01:32 2024 UTC