
(?(-1)then|else) where -1 is a negative integer and then and else are any valid regexesĬonditional 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. ( a ) ? (?(1) b | c ) matches ab, the first c, and the second c in babxcac If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match.


(?(1)then|else) where 1 is the number of a capturing group and then and else are any valid regexes (?'one' a ) ? (?('one') b | c ) matches ab, the first c, and the second c in babxcac (?('name')then|else) where name is the name of a capturing group and then and else are any valid regexes (? a ) ? (?() b | c ) matches ab, the first c, and the second c in babxcac 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. (?()then|else) where name is the name of a capturing group and then and else are any valid regexes (? a ) ? (?(one) b | c ) matches ab, the first c, and the second c in babxcac T (?! s ) matches the first t in streets. Similar to positive lookahead, except that negative lookahead only succeeds if the regex inside the lookahead fails to match. T (?= s ) matches the second t in streets. In a pattern like one (?= two ) three, both two and three have to match at the position where the match of one ends. It does not consume any characters or expand the match. Matches at a position where the pattern inside the lookahead can be matched.

But it will not backtrack into the group to try other permutations of the group.Ī (?> bc | b ) c matches abcc but not abc If the remainder of the regex fails, the engine may backtrack over the group if a quantifier or alternation makes it optional. ( 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Ītomic groups prevent the regex engine from backtracking back into the group after a match has been found for the group. 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. Regular Expression Reference: Special GroupsĮverything between (?# and ) is ignored by the regex engine.
