What it does
Named groups give a capture a name as well as a number. The syntax differs by engine.
How to use it
- Load the example.
- Switch engines and compare the syntax each one needs.
- Check the counterexample.
Verified example
Example
Text "TX-00057"
(?<id>TX-\d{5}) Result: "TX-00057"; groups "TX-00057"
(?P<id>TX-\d{5}) Result: "TX-00057"; groups "TX-00057"
(?<id>TX-\d{5}) Result: "TX-00057"; groups "TX-00057"
(?P<id>TX-\d{5}) Result: "TX-00057"; groups "TX-00057"
Counterexample
Text "TX-7"
(?<id>TX-\d{5}) Result: no match
(?P<id>TX-\d{5}) Result: no match
(?<id>TX-\d{5}) Result: no match
(?P<id>TX-\d{5}) Result: no match
Recorded by running fixture FX-S05 on : rp.js@1 on Node v24.21.0 (V8), v24.21.0, CPython 3.14.2 (Pyodide 314.0.7), PCRE2 10.48, go1.27.1. JavaScript results come from the rp.js@1 core on Node’s V8; your browser runs the same core.
Engines
- JavaScript and PCRE2 accept (?<id>…); Python re and Go need (?P<id>…). Changing the engine label does not change the syntax.
Limits
- Duplicate names follow each engine’s own rules.