Replacement Reference |
Characters |
Matched Text & Backreferences |
Context & Case Conversion |
Conditionals |
Feature | Syntax | Description | Example | JGsoft | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | 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 | YES | 7 | 5.10 | 7.0 | YES | 5.2.2 | YES | YES | YES | no | YES | no | 1.9 | no | ECMA 1.42–1.85 | no | no | 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 | YES | no | 5.10 | 7.0 | YES | 5.2.2 | YES | YES | no | no | no | no | 1.9 | no | ECMA 1.42–1.85 | no | no | 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 | no | no | 5.10 | YES | YES | YES | YES | YES | no | no | YES | YES | no | no | 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 | YES | 7 error | 5.10 | 6.7 option | option | 5.2.0 option | option | option | error | n/a | error | error | 1.9 | n/a | ECMA 1.42–1.85 | n/a | n/a | 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 | YES | n/a | no | no | no | no | no | no | n/a | n/a | n/a | n/a | no | n/a | no | n/a | n/a | 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 | no | n/a | no | 6.7–8.33 | no | 5.2.0–5.5.9 | XE–XE6 | 2.14.0–3.0.2 | n/a | n/a | n/a | n/a | no | n/a | no | n/a | n/a | 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 | no | n/a | 5.10 | 8.36 | YES | 5.6.9 | 10.2 | 3.1.3 | n/a | n/a | n/a | n/a | no | n/a | ECMA 1.47–1.85 | n/a | n/a | 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 | no | n/a | no | no | no | no | no | no | n/a | n/a | n/a | n/a | no | n/a | ECMA 1.42–1.46 | n/a | n/a | 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 | no | n/a | no | no | no | no | no | no | n/a | n/a | n/a | n/a | 1.9 | n/a | no | n/a | n/a | 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 | YES | 7 | 5.10 | 7.0 | YES | 5.2.2 | YES | YES | YES | no | YES | no | 1.9 | no | ECMA 1.47–1.85 | no | no | 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 | YES | no | 5.10 | 7.0 | YES | 5.2.2 | YES | YES | no | no | no | no | 1.9 | no | ECMA 1.47–1.85 | no | no | 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 | 5.10 | 7.2 | YES | 5.2.4 | YES | YES | no | no | no | no | no | no | ECMA 1.47–1.85 | no | no | 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 | 5.10 | 7.2 | YES | 5.2.4 | YES | YES | no | no | no | no | no | no | ECMA 1.42–1.85 | no | no | 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 | no | no | 5.10 | YES | YES | YES | YES | YES | no | no | no | YES | no | no | 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 | non‑ECMA | 7 | 5.10 | YES | YES | YES | YES | YES | ignored | n/a | ignored | YES | 1.9 | n/a | ECMA 1.47–1.85 | n/a | n/a | 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 | YES | 7 | 5.10 | 6.5 | YES | 5.1.3 | YES | YES | ignored | n/a | ignored | 2.4–3.4 fail | 1.9 fail | n/a | ECMA 1.78–1.85 fail | n/a | n/a | 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 | YES | 7 error | 5.10 | 6.7 | YES | 5.2.0 | YES | YES | ignored | n/a | error | error | 1.9 error | n/a | ECMA 1.42–1.85 error | n/a | n/a | 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 | YES | 7 error | 5.10 error | 4.0–8.33 | error | 5.0.0–5.1.2 | XE–XE6 | 2.14.0–3.0.2 | error | n/a | error | error | 1.9 error | n/a | ECMA 1.42–1.85 | n/a | n/a | 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 | YES | n/a | n/a | no | n/a | no | no | no | n/a | n/a | n/a | n/a | n/a | n/a | no | n/a | n/a | 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 | YES | n/a | n/a | 4.0–8.33 | n/a | 5.0.0–5.1.2 | XE–XE6 | 2.14.0–3.0.2 | n/a | n/a | n/a | n/a | n/a | n/a | ECMA 1.42–1.85 error | n/a | n/a | 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 | 7 error | 5.10 error | error | error | error | error | error | error | n/a | error | error | 1.9 error | n/a | ECMA 1.42–1.85 | n/a | n/a | 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 | ECMA 1.42–1.85 error | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | |
Feature | Syntax | Description | Example | JGsoft | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | Oracle | XML | XPath |
| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |
| Introduction | Table of Contents | Quick Reference | Characters | Basic Features | Character Classes | Shorthands | Anchors | Word Boundaries | Quantifiers | Unicode | Capturing Groups & Backreferences | Named Groups & Backreferences | Special Groups | Mode Modifiers | Recursion & Balancing Groups |
| Characters | Matched Text & Backreferences | Context & Case Conversion | Conditionals |
Page URL: https://www.regular-expressions.info/refext.html
Page last updated: 16 August 2024
Site last updated: 06 November 2024
Copyright © 2003-2024 Jan Goyvaerts. All rights reserved.