Lookahead & Lookbehind Guide
learn lookahead and lookbehind assertions with interactive examples
By Bikram NathLast updated
Zero-width assertions let a regex match a position without consuming characters. Feed (?<=\$)\d+(\.\d+)? to this tool and it highlights just the numeric part of $19.99, leaving the dollar sign outside the match -- something a plain capture group cannot do in one step. The color-coded visualization shows at a glance which assertion is gating or passing each position in the input.
Try it now — free, instant, no signup
What is Lookahead & Lookbehind Guide?
This tool lets you write and test all four assertion types -- positive lookahead (?=...), negative lookahead (?!...), positive lookbehind (?<=...), and negative lookbehind (?<!...) -- against live input. Enter hunter2A! with the pattern ^(?=.*[A-Z])(?=.*\d)(?=.*[!@#]).*$ and each assertion lights up a distinct color, making it immediately visible which sub-check passes or fails at a given cursor position.
Reach for this when you are learning the mechanics of zero-width assertions and want a focused environment. regex101 also supports all four types and adds a detailed sidebar breakdown with a community library of saved patterns, which is better for debugging a complex multi-assertion pattern that is already partially working. This tool's narrower scope makes it faster for experimentation when the assertions themselves are still unfamiliar.
Lookbehind support arrived in ECMAScript 2018. Chrome 62+, Edge 79+, and Node.js 8+ all ship it, but Safari only added support in version 16.4, released March 2023. JavaScript engines also reject variable-length lookbehinds: (?<=\d+) throws a SyntaxError in V8 and SpiderMonkey alike. Use a bounded quantifier such as (?<=\d{1,6}) as a workaround when porting patterns from Python or PCRE.