| Replacement Reference |
| Characters |
| Matched Text & Backreferences |
| Case Conversion |
| Context |
| Conditionals |
| 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Capturing group | (regex) | Parentheses group the regex between them. They capture the text matched by the regex inside them into a numbered group that can be reused with a numbered backreference. They allow you to apply regex operators to the entire grouped regex. | (abc){3} matches abcabcabc. First group matches abc. | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | extended | extended | YES | YES | YES |
| Capturing group | \(regex\) | Escaped parentheses group the regex between them. They capture the text matched by the regex inside them into a numbered group that can be reused with a numbered backreference. They allow you to apply regex operators to the entire grouped regex. | \(abc\){3} matches abcabcabc. First group matches abc. | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | basic grep | basic grep | no | basic | basic | no | no | no |
| Capturing group | 100 or more capturing groups supported in a single regular expression. | YES | 3.5 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | no | YES | YES | VC’12 | YES | YES | YES | YES | YES | YES | YES | ||
| Non-capturing group | (?:regex) | Non-capturing parentheses group the regex so you can apply regex operators, but do not capture anything. | (?:abc){3} matches abcabcabc. No groups. | YES | YES | YES | YES | YES | YES | YES | YES | default | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 3 |
| Branch reset group | (?|regex) | If the regex inside the branch reset group has multiple alternatives with capturing groups, then the capturing group numbers are the same in all the alternatives. | (x)(?|(a)|(bc)|(def))\2 matches xaa, xbcbc, or xdefdef with the first group capturing x and the second group capturing a, bc, or def | V2 | 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 |
| Atomic group | (?>regex) | Atomic groups prevent the regex engine from backtracking into the group after a match has been found for the group. If the remainder of the regex fails then the engine may backtrack over the group if a quantifier or alternation makes it optional or backtrack to something prior to the group. But it will not backtrack into the group to try other permutations of the group. | a(?>bc|b)c matches abcc but not abc | YES | 3.11 | no | no | no | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | YES | no | ECMA | no | no | no | no | no | no |
| Atomic group | (*atomic:regex) | Alternate syntax for the above. | a(*atomic:bc|b)c matches abcc but not abc | no | no | no | no | no | no | no | no | no | 5.28 | no | 10.33 | 7.4.0 | no | 4.0.0 | no | no | no | no | no | no | no | no | no |
| Comment | (?#comment) | Everything between (?# and ) is ignored by the regex engine. | a(?#foobar)b matches ab | YES | YES | no | no | YES | YES | no | YES | no | YES | YES | YES | YES | YES | YES | YES | no | ECMA | YES | no | no | no | no | no |
| Backreference | \1 through \9 | Substituted with the text matched between the 1st through 9th numbered capturing group. | (abc|def)=\1 matches abc=abc or def=def, but not abc=def or def=abc. | YES | YES | YES | YES | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | YES | ECMA basic grep | ECMA basic grep | YES | basic | YES | YES | no | YES |
| Backreference | \10 through \99 | Substituted with the text matched between the 10th through 99th numbered capturing group. | YES | YES | YES | YES | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | YES | ECMA | no | YES | no | no | no | no | YES | |
| Backreference | \10 through \99 | Substituted with the text matched between the 1st through 9th numbered capturing group followed by a literal digit if the regex has less than 10 capturing groups. | (a)\17 matches aa7. | YES | no | no | YES | no | ECMA | YES | YES | no | no | no | no | no | no | no | no | no | ECMA basic grep | no | basic | YES | YES | no | YES |
| Backreference | \100 through \999 | Substituted with the text matched between the 100th through 999th numbered capturing group. | no | no | YES | no | YES | YES | YES | YES | no | YES | YES | YES | YES | no | YES | YES | ECMA VC’12 | no | YES | no | no | no | no | YES | |
| Backreference | \100 through \999 | Substituted with the text matched between the 10th through 99th numbered capturing group followed by a literal digit if the regex has less than 100 capturing groups. | YES | no | no | no | no | ECMA | YES | YES | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | YES | |
| Backreference | \k<1>, \k<2>, etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\k<1> matches abc=abc or def=def, but not abc=def or def=abc. | YES | no | no | no | YES | YES | no | no | no | no | no | no | no | no | no | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
| Backreference | \k'1', \k'2', etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\k'1' matches abc=abc or def=def, but not abc=def or def=abc. | YES | no | no | no | no | YES | no | no | no | no | no | no | no | no | no | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
| Backreference | \g1, \g2, etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\g1 matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | no | no | ECMA 1.42 | no | no | no | no | no | no |
| Backreference | \g{1}, \g{2}, etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\g{1} matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | no | no | ECMA 1.42 | no | no | no | no | no | no |
| Backreference | \g<1>, \g<2>, etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\g<1> matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | ECMA 1.47 | no | no | no | no | no | no |
| Backreference | \g'1', \g'2', etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=\g'1' matches abc=abc or def=def, but not abc=def or def=abc. | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | ECMA 1.47 | no | no | no | no | no | no |
| Backreference | (?P=1), (?P=2), etc. | Substituted with the text matched by the capturing group with the specified number. | (abc|def)=(?P=1) matches abc=abc or def=def, but not abc=def or def=abc. | YES | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no |
| Relative Backreference | \k<-1>, \k<-2>, etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\k<-3> matches abcdb. | V2 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
| Relative Backreference | \k'-1', \k'-2', etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\k'-3' matches abcdb. | V2 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | 1.9 | no | ECMA 1.47 | no | no | no | no | no | no |
| Relative Backreference | \g-1, \g-2, etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\g-3 matches abcdb. | no | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | no | no | ECMA 1.42 | no | no | no | no | no | no |
| Relative Backreference | \g{-1}, \g{-2}, etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\g{-3} matches abcdb. | no | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | no | no | ECMA 1.42 | no | no | no | no | no | no |
| Relative Backreference | \g<-1>, \g<-2>, etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\g<-3> matches abcdb. | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | ECMA 1.47 | no | no | no | no | no | no |
| Relative Backreference | \g'-1', \g'-2', etc. | Substituted with the text matched by the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the backreference. | (a)(b)(c)(d)\g'-3' matches abcdb. | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | ECMA 1.47 | no | no | no | no | no | no |
| Failed backreference | Any numbered backreference | Backreferences to groups that did not participate in the match attempt fail to match. | (a)?\1 matches aa but fails to match b. | YES | YES | ignored | ignored | ignored | non‑ECMA | YES | YES | n/a | YES | YES | YES | YES | YES | YES | YES | ECMA basic grep ignored | ECMA 1.47 | YES | basic | YES | YES | n/a | ignored |
| Invalid backreference | Any numbered backreference | Backreferences to groups that do not exist at all are valid but fail to match anything. | (a)?\2|b matches b in aab. | error | error | error | error | error | error | YES | error | n/a | error | error | error | error | error | error | 1.8 only | ECMA basic grep error | ECMA basic grep error | error | basic error | error | error | n/a | error |
| Nested backreference | Any numbered backreference | Backreferences can be used inside the group they reference. | (a\1?){3} matches aaaaaa. | YES | error | ignored | YES | ignored | YES | YES | YES | n/a | YES | YES | YES | YES | YES | YES | fail | ECMA basic grep error | ECMA 1.78 fail | error | basic error | error | YES | n/a | ignored |
| Forward reference | Any numbered backreference | Backreferences can be used before the group they reference. | (\2?(a)){3} matches aaaaaa. | YES | error | ignored | error | error | non‑ECMA | YES | YES | n/a | YES | YES | YES | YES | YES | YES | YES | ECMA basic grep error | ECMA 1.78 | error | basic error | error | error | n/a | error |
| 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/refcapture.html
Page last updated: 9 June 2025
Site last updated: 29 October 2025
Copyright © 2003-2025 Jan Goyvaerts. All rights reserved.