php / php/doc-en

Duplicate reference subpattern `(?|` also allows repetition of named subpatterns

Open Beginner friendly
#893 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Extension: pcre
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

This section only mentions duplicate numbered subpatterns inside the (?| … ) grouping, but it also supports named subpatterns, e.g.:

preg_match_all('/(?|(?P<x>f)oo|(?P<x>b)(ar|az))/', 'foo bar baz qux', $m);
var_dump($m);

yields:

array(4) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "foo"
    [1]=>
    string(3) "bar"
    [2]=>
    string(3) "baz"
  }
  ["x"]=>
  array(3) {
    [0]=>
    string(1) "f"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "b"
  }
  [1]=>
  array(3) {
    [0]=>
    string(1) "f"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "b"
  }
  [2]=>
  array(3) {
    [0]=>
    string(0) ""
    [1]=>
    string(2) "ar"
    [2]=>
    string(2) "az"
  }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open reference/pcre/pattern.syntax.xml at the linked section around line 1502 and compare its description with the supplied PHP example. Update the section to mention named subpatterns in duplicate-reference groups, including the demonstrated behavior; done when the documentation accurately covers both numbered and named subpatterns.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.