Skip to content
uencoder

Regex Advanced Syntax Reference

Reference for advanced regex features: lookaround, backreferences, atomic groups, and possessive quantifiers.

Lookaround Assertions

Lookahead (?=...) and negative lookahead (?!...) assert what follows without consuming. Lookbehind (?<=...) and negative lookbehind (?<!...) assert what precedes. Fixed-width lookbehind is widely supported; variable-width is supported in .NET, PCRE 7.7+, and ECMAScript 2018+. Lookaround does not consume characters, allowing overlapping matches. Nested lookaround can express complex conditions but may be slow or unsupported. Lookaround is zero-width: it matches a position, not text.

(?=...)
Positive lookahead
asserts ahead
(?!...)
Negative lookahead
asserts not ahead
(?<=...)
Positive lookbehind
asserts behind

Advanced Constructs

Backreferences \1 match the same text as a previous capturing group. Atomic groups (?>...) prevent backtracking within the group, improving performance and changing semantics. Possessive quantifiers (++, *+, ?+) are shorthand for atomic groups. Named groups (?<name>...) and references \k<name> improve readability. Conditional patterns (?(1)yes|no) match based on group participation. Subroutine calls (?1) reuse a group pattern. These features vary by engine.

backreference
Match prior group
\1, \k<name>
atomic (?>)
No backtracking
performance + semantics
possessive
x++ = (?>x+)
no giveback

Related tools

References