| 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Positive lookahead | (?=regex) | Matches at a position where the pattern inside the lookahead can be matched. Matches only the position. It does not consume any characters or expand the match. In a pattern like one(?=two)three, both two and three have to match beginning at the position where the match of one ends (which is only possible if two and three represent regexes that can match the same text rather than the literal words). | t(?=s) matches the second t in streets. | YES | YES | YES | YES | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | no |
| Negative lookahead | (?!regex) | Similar to positive lookahead, except that negative lookahead only succeeds if the regex inside the lookahead fails to match. | t(?!s) matches the first t in streets. | YES | YES | YES | YES | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | no |
| Positive lookbehind | (?<=regex) | Matches at a position if the pattern inside the lookbehind can be matched ending at that position. | (?<=s)t matches the first t in streets. | YES | YES | YES | no | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | 1.9 | no | ECMA | no | no | no | no | no | no |
| Negative lookbehind | (?<!regex) | Matches at a position if the pattern inside the lookbehind cannot be matched ending at that position. | (?<!s)t matches the second t in streets. | YES | YES | YES | no | YES | YES | YES | YES | no | YES | YES | YES | YES | YES | YES | 1.9 | no | ECMA | no | no | no | no | no | no |
| Lookbehind | Any lookbehind with alternation | Alternatives inside lookbehind can differ in length. | (?<=is|e)t matches the second and fourth t in twisty streets. | YES | no | YES | n/a | YES | YES | YES | YES | n/a | 5.30 | YES | YES | YES | YES | YES | 1.9 | n/a | ECMA | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | Any lookbehind and bounded quantifier | Quantifiers with a finite maximum number of repetitions can be used inside lookbehind. | (?<=s\w{1,7})t matches only the fourth t in twisty streets. | YES | no | YES | n/a | YES | YES | 6 4 fail | YES | n/a | 5.36 5.30 fail | no | 10.43 | no | no | 4.4.0 | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | Any lookbehind and backreference | Backreferences can be used inside lookbehind. Syntax prohibited in lookbehind is also prohibited in the referenced capturing group. | (\w).+(?<=\1) matches twisty street in twisty streets. | YES | 3.5 | YES | n/a | YES | YES | no | no | n/a | no | no | 10.23 | 7.3.0 | no | 4.0.0 | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | Any lookbehind | The full regular expression syntax can be used inside lookbehind. The lookbehind’s regex is matched from right to left. | (?<=s\w+)t matches only the fourth t in twisty streets. | YES | no | YES | n/a | YES | YES | 13 | no | n/a | no | no | no | no | no | no | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | Any lookbehind | The lookbehind’s regex is matched from left to right, stepping through the subject string from left to right (from longest possible lookbehind to shortest possible lookbehind). | (?<=bc|c|(abc))d captures abc as the first group when the regex matches d in abcd. | no | no | no | n/a | no | no | no | no | n/a | 5.30 | no | no | no | no | no | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | Any lookbehind | The lookbehind’s regex is matched from left to right, stepping through the subject string from right to left (from shortest possible lookbehind to longest possible lookbehind). | (?<=bc|(c)|abc)d captures c as the first group when the regex matches d in abcd. | no | no | no | n/a | no | no | YES | YES | n/a | no | no | no | no | no | no | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a |
| Lookbehind | (?<=regex) or (?<!regex) | Lookbehind is atomic. Only relevant if the lookbehind contains a capturing group and the remainder of the regex has a backreference to that group. | YES | no | YES | n/a | YES | YES | 6 | YES | n/a | 5.36 | YES | YES | YES | YES | YES | no | n/a | no | n/a | n/a | n/a | n/a | n/a | n/a | |
| Positive lookahead | (*positive_lookahead:regex) | Matches at a position where the pattern inside the lookahead can be matched. Matches only the position. It does not consume any characters or expand the match. Atomic. | t(*positive_lookahead:s) matches the second t in streets. | 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 |
| Positive lookahead | (*pla:regex) | Short form of the above. | t(*pla:s) matches the second t in streets. | 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 |
| Negative lookahead | (*negative_lookahead:regex) | Similar to positive lookahead, except that negative lookahead only succeeds if the regex inside the lookahead fails to match. Atomic. | t(*negative_lookahead:s) matches the first t in streets. | 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 |
| Negative lookahead | (*nla:regex) | Short form of the above. | t(*nla:s) matches the first t in streets. | 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 |
| Positive lookbehind | (*positive_lookbehind:regex) | Matches at a position if the pattern inside the lookbehind can be matched ending at that position. Atomic. | (*positive_lookbehind:s)t matches the first t in streets. | 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 |
| Positive lookbehind | (*plb:regex) | Short form of the above. | (*plb:s)t matches the first t in streets. | 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 |
| Negative lookbehind | (*negative_lookbehind:regex) | Matches at a position if the pattern inside the lookbehind cannot be matched ending at that position. Atomic. | (*negative_lookbehind:s)t matches the second t in streets. | 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 |
| Negative lookbehind | (*nlb:regex) | Short form of the above. | (*nlb:s)t matches the second t in streets. | 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 |
| Positive lookahead | (*non_atomic_positive_lookahead:regex) | Non-atomic lookahead can be backtracked into to try different alternatives if the remainder of the regex fails to match. Only relevant if the lookahead contains a capturing group and the remainder of the regex has a backreference to that group. | no | no | no | no | no | no | no | no | no | no | no | 10.34 | 7.4.6 | no | 4.2.0 | no | no | no | no | no | no | no | no | no | |
| Positive lookahead | (*napla:regex) | Short form of the above. | no | no | no | no | no | no | no | no | no | no | no | 10.34 | 7.4.6 | no | 4.2.0 | no | no | no | no | no | no | no | no | no | |
| Positive lookbehind | (*non_atomic_positive_lookbehind:regex) | Non-atomic lookbehind can be backtracked into to try different alternatives if the remainder of the regex fails to match. Only relevant if the lookbehind contains a capturing group and the remainder of the regex has a backreference to that group. | no | no | no | no | no | no | no | no | no | no | no | 10.34 | 7.4.6 | no | 4.2.0 | no | no | no | no | no | no | no | no | no | |
| Positive lookbehind | (*naplb:regex) | Short form of the above. | no | no | no | no | no | no | no | no | no | no | no | 10.34 | 7.4.6 | no | 4.2.0 | no | no | no | no | no | no | no | no | no | |
| Keep text out of the regex match | \K | The text matched by the part of the regex to the left of the \K is omitted from the overall regex match. Other than that the regex is matched normally from left to right. Capturing groups to the left of the \K capture as usual. | st matches only the first t in streets. | V2 | no | no | no | no | no | no | no | no | YES | 7.2 | YES | YES | YES | YES | 2.0 | no | ECMA 1.42 | no | no | no | no | no | no |
| Lookaround conditional | (?(?=regex)then|else) where (?=regex) is any valid lookaround and then and else are any valid regexes | If the lookaround succeeds, the “then” part must match for the overall regex to match. If the lookaround fails, the “else” part must match for the overall regex to match. The lookaround is zero-length. The “then” and “else” parts consume their matches like normal regexes. | (?(?<=a)b|c) matches the second b and the first c in babxcac | YES | no | no | no | no | YES | no | no | no | YES | YES | YES | YES | YES | YES | no | no | ECMA | no | no | no | no | no | no |
| Implicit lookahead conditional | (?(regex)then|else) where regex, then, and else are any valid regexes and regex is not the name of a capturing group | If “regex” is not the name of a capturing group, then it is interpreted as a lookahead as if you had written (?(?=regex)then|else). If the lookahead succeeds, the “then” part must match for the overall regex to match. If the lookahead fails, the “else” part must match for the overall regex to match. The lookaround is zero-length. The “then” and “else” parts consume their matches like normal regexes. | (?(\d{2})7|c) matches the first 7 and the c in 747c | no | no | no | no | no | YES | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no |
| Named conditional | (?(name)then|else) where name is the name of a capturing group and then and else are any valid regexes | If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (?<one>a)?(?(one)b|c) matches ab, the first c, and the second c in babxcac | YES | YES | no | no | no | YES | no | no | no | no | 6.7 | YES | YES | YES | YES | no | no | no | no | no | no | no | no | no |
| Named conditional | (?(<name>)then|else) where name is the name of a capturing group and then and else are any valid regexes | If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (?<one>a)?(?(<one>)b|c) matches ab, the first c, and the second c in babxcac | V2 | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | 2.0 | no | ECMA 1.42 | no | no | no | no | no | no |
| Named conditional | (?('name')then|else) where name is the name of a capturing group and then and else are any valid regexes | If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (?'one'a)?(?('one')b|c) matches ab, the first c, and the second c in babxcac | V2 | no | no | no | no | no | no | no | no | YES | 7.0 | YES | YES | YES | YES | 2.0 | no | ECMA 1.42 | no | no | no | no | no | no |
| Conditional | (?(1)then|else) where 1 is the number of a capturing group and then and else are any valid regexes | If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (a)?(?(1)b|c) matches ab, the first c, and the second c in babxcac | YES | YES | no | no | no | YES | no | no | no | YES | YES | YES | YES | YES | YES | 2.0 | no | ECMA | no | no | no | no | no | no |
| Relative conditional | (?(-1)then|else) where -1 is a negative integer and then and else are any valid regexes | Conditional that tests 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 immediately before the conditional. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (a)?(?(-1)b|c) matches ab, the first c, and the second c in babxcac | V2 | no | no | no | no | no | no | no | no | no | 7.2 | YES | YES | YES | YES | no | no | no | no | no | no | no | no | no |
| Forward conditional | (?(+1)then|else) where +1 is a positive integer and then and else are any valid regexes | Conditional that tests 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 left to right starting at the “then” part of conditional. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | ((?(+1)b|c)(d)?){2} matches cc and cdb in bdbdccxcdcxcdb | V2 | no | no | no | no | no | no | no | no | no | 7.2 | YES | YES | YES | YES | no | no | no | no | no | no | no | no | no |
| Conditional | (?(+1)then|else) where 1 is the number of a capturing group and then and else are any valid regexes | The + is ignored and the number is taken as an absolute reference to a capturing group. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. | (a)?(?(+1)b|c) matches ab, the first c, and the second c in babxcac | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | |
| 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/refadv.html
Page last updated: 8 January 2026
Site last updated: 09 January 2026
Copyright © 2003-2026 Jan Goyvaerts. All rights reserved.