Assert that something precedes, without including it
(?<=...) is lookahead's mirror image: "at the current position, the pattern inside the lookbehind matches the text immediately BEFORE this position." Same zero-width semantics — the matched text isn't part of the capture.
The classic use: extract values after a marker
Extract the price after '$': (?<=\$)\d+(\.\d+)?. The lookbehind asserts a '$' precedes; the actual match is just the number. Without it, you'd capture '$19.99' and slice off the '$' in code.
Same pattern works for any prefix marker: extract user IDs after 'user_', extract dates after 'on ', extract whatever-comes-after-X without including X.
The width restriction (HUGE)
Most engines require the lookbehind pattern to be fixed-width — every alternative inside must match the same number of characters.
- Java, .NET, Python's
re: Fixed-width only.(?<=cat)works (3 chars);(?<=cat|elephant)may fail or behave wrong. - Python's
regexmodule, PCRE 8+: Variable-width allowed. - JavaScript: Variable-width since ES2018.
- RE2 / Go: Lookbehind NOT supported at all.
This is the most fragmented feature in regex. Always check your engine's docs before relying on lookbehind.