Feature | Syntax | Description | Example | JGsoft | Python | JavaScript | VBScript | XRegExp | .NET | Java | ICU | RE2 | Perl | PCRE | PCRE2 | PHP | Delphi | R | Ruby | std::regex | Boost | Tcl | POSIX | GNU | Oracle | XML | XPath |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Named capturing group | (?<name>regex) | Captures the text matched by "regex" into the group "name". The name can contain letters and numbers but must start with a letter. | (?<x>abc){3} matches abcabcabc. The group x matches abc. | YES | no | YES | no | YES | YES | 7 | YES | default 2023/09 | YES | 7.0 | YES | YES | YES | YES | 1.9 | no | ECMA 1.42 | no | no | no | no | no | no |
Named capturing group | (?'name'regex) | Captures the text matched by "regex" into the group "name". The name can contain letters and numbers but must start with a letter. | (?'x'abc){3} matches abcabcabc. The group x matches abc. | YES | no | no | no | no | YES | no | no | no | YES | 7.0 | YES | YES | YES | YES | 1.9 | no | ECMA 1.42 | no | no | no | no | no | no |
Named capturing group | (?P<name>regex) | Captures the text matched by "regex" into the group "name". The name can contain letters and numbers but must start with a letter. | (?P<x>abc){3} matches abcabcabc. The group x matches abc. | YES | YES | no | no | YES | no | no | no | default | YES | YES | YES | YES | YES | YES | no | no | no | no | no | no | no | no | no |
Duplicate named group | Any named group | Two named groups can share the same name. | (?<x>a)|(?<x>b) matches a or b. | YES | error | error | n/a | error | YES | 7 error | error | default | YES | 6.7 option | option | option | option | option | 1.9 | n/a | ECMA 1.42 | n/a | n/a | n/a | n/a | n/a | n/a |
Duplicate named group | Any named group | Named groups that share the same name are treated as one an the same group, so there are no pitfalls when using backreferences to that name. | YES | n/a | n/a | n/a | n/a | YES | n/a | n/a | no | no | no | no | no | no | no | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a | |
Duplicate named group | Any named group | If a regex has multiple groups with the same name, backreferences using that name point to the leftmost group in the regex with that name. | no | n/a | n/a | n/a | n/a | no | n/a | n/a | default | no | 6.7–8.33 | no | 5.5.0–5.5.9 | XE–XE6 | 2.14.0–3.0.2 | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a | |
Duplicate named group | Any named group | If a regex has multiple groups with the same name, backreferences using that name point to the leftmost group with that name that has actually participated in the match attempt when the backreference is evaluated. | no | n/a | n/a | n/a | n/a | no | n/a | n/a | no | YES | 8.36 | YES | 5.6.9 | 10.2 | 3.1.3 | no | n/a | ECMA 1.47 | n/a | n/a | n/a | n/a | n/a | n/a | |
Duplicate named group | Any named group | If a regex has multiple groups with the same name, backreferences using that name point to the rightmost group with that name that appears to the left of the backreference in the regex. | no | n/a | n/a | n/a | n/a | no | n/a | n/a | no | no | no | no | no | no | no | no | n/a | ECMA 1.42–1.46 | n/a | n/a | n/a | n/a | n/a | n/a | |
Duplicate named group | Any named group | If a regex has multiple groups with the same name, backreferences using that name can match the text captured by any group with that name that appears to the left of the backreference in the regex. | no | n/a | n/a | n/a | n/a | no | n/a | n/a | no | no | no | no | no | no | no | 1.9 | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a | |
Duplicate named group | Any named group | If a regex has multiple groups with the same name, the regex engine returns the text matched by the last group with that name to participate in the match. | no | n/a | n/a | n/a | n/a | no | n/a | n/a | no | no | no | no | YES | YES | no | 1.9 | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a | |
Named backreference | \k<name> | Substituted with the text matched by the named group "name". | (?<x>abc|def)=\k<x> matches abc=abc or def=def, but not abc=def or def=abc. | YES | no | YES | no | YES | YES | 7 | YES | no | YES | 7.0 | YES | YES | YES | YES | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
Named backreference | \k'name' | Substituted with the text matched by the named group "name". | (?'x'abc|def)=\k'x' matches abc=abc or def=def, but not abc=def or def=abc. | YES | no | no | no | no | YES | no | no | no | YES | 7.0 | YES | YES | YES | YES | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
Named backreference | \k{name} | Substituted with the text matched by the named group "name". | (?'x'abc|def)=\k{x} matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | YES | 7.2 | YES | YES | YES | YES | no | no | ECMA 1.47 | no | no | no | no | no | no |
Named backreference | \g{name} | Substituted with the text matched by the named group "name". | (?'x'abc|def)=\g{x} matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | YES | 7.2 | YES | YES | YES | YES | no | no | ECMA 1.42 | no | no | no | no | no | no |
Named backreference | (?P=name) | Substituted with the text matched by the named group "name". | (?P<x>abc|def)=(?P=x) matches abc=abc or def=def, but not abc=def or def=abc. | YES | YES | no | no | no | no | no | no | no | YES | YES | YES | YES | YES | YES | no | no | no | no | no | no | no | no | no |
Failed backreference | Any named backreference | Backreferences to groups that did not participate in the match attempt fail to match. | (?<x>a)?\k<x> matches aa but fails to match b. | YES | YES | ignored | n/a | ignored | non‐ECMA | 7 | YES | n/a | YES | YES | YES | YES | YES | YES | 1.9 | n/a | ECMA 1.47 | n/a | n/a | n/a | n/a | n/a | n/a |
Nested backreference | Any named backreference | Backreferences can be used inside the group they reference. | (?<x>a\k<x>?){3} matches aaaaaa. | YES | 2.4–3.4 fail | ignored | n/a | ignored | YES | 7 | YES | n/a | YES | 6.5 4.5 error | YES | YES | YES | YES | 1.9 fail | n/a | ECMA 1.78 fail | n/a | n/a | n/a | n/a | n/a | n/a |
Forward reference | Any named backreference | Backreferences can be used before the group they reference. | (\k<x>?(?<x>a)){3} matches aaaaaa. | YES | error | ignored | n/a | error | YES | 7 error | error | n/a | YES | 6.7 4.5 error | YES | YES | YES | YES | 1.9 error | n/a | ECMA 1.42 error | n/a | n/a | n/a | n/a | n/a | n/a |
Named capturing group | Any named capturing group | A number is a valid name for a capturing group. | (?<17>abc){3} matches abcabcabc. The group named "17" matches abc. | YES | error | error | n/a | error | YES | 7 error | error | default | error | 4.5–8.33 | error | error | XE–XE6 | 2.14.0–3.0.2 | 1.9 error | n/a | ECMA 1.42 | n/a | n/a | n/a | n/a | n/a | n/a |
Named backreference | Any named backreference | A number is a valid name for a backreference which then points to a group with that number as its name. | (?<17>abc|def)=\k<17> matches abc=abc or def=def, but not abc=def or def=abc. | YES | n/a | n/a | n/a | n/a | YES | n/a | n/a | default error | n/a | 4.5–8.33 | n/a | n/a | XE–XE6 | 2.14.0–3.0.2 | n/a | n/a | ECMA 1.42 error | n/a | n/a | n/a | n/a | n/a | n/a |
Named capturing group | Any capturing group with a number as its name | If the name of the group is a number, that becomes the group’s name and the group’s number. | (?<17>abc|def)=17円 matches abc=abc or def=def, but not abc=def or def=abc. | no | n/a | n/a | n/a | n/a | YES | n/a | n/a | no | n/a | no | n/a | n/a | no | no | n/a | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
Named capturing group | Any named capturing group | A negative number is a valid name for a capturing group. | (?<-17>abc){3} matches abcabcabc. The group named "-17" matches abc. | error | error | error | n/a | error | error | 7 error | error | default error | error | error | error | error | error | error | 1.9 error | n/a | ECMA 1.42 | n/a | n/a | n/a | n/a | n/a | n/a |
Named backreference | Any named backreference | A negative number is a valid name for a backreference which then points to a group with that negative number as its name. | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | ECMA 1.42 error | n/a | n/a | n/a | n/a | n/a | n/a | |
Feature | Syntax | Description | Example | JGsoft | Python | JavaScript | VBScript | XRegExp | .NET | Java | ICU | RE2 | Perl | PCRE | PCRE2 | PHP | Delphi | R | Ruby | std::regex | Boost | Tcl | POSIX | GNU | Oracle | XML | XPath |
| Quick Start | Tutorial | Search & Replace | Tools & Languages | Examples | Reference |
| Introduction | Table of Contents | Quick Reference | Characters | Basic Features | Character Classes | Shorthands | Anchors | Word Boundaries | Quantifiers | Capturing Groups & Backreferences | Named Groups & Backreferences | Special Groups | Unicode Characters and Properties | Unicode Versions | Unicode Categories | Unicode Scripts | Unicode Blocks | Unicode Binary Properties | Unicode Property Sets | Unicode Boundaries | Mode Modifiers | Recursion & Balancing Groups | Backtracking Control Verbs |
| Characters | Matched Text & Backreferences | Case Conversion | Context | Conditionals |
Page URL: https://www.regular-expressions.info/refext.html
Page last updated: 9 June 2025
Site last updated: 14 October 2025
Copyright © 2003-2025 Jan Goyvaerts. All rights reserved.