Lookahead & Lookbehind Guide
learn lookahead and lookbehind assertions with interactive examples
Interactive Lookahead & Lookbehind Guide — coming soon
In development. We're still building the interactive Lookahead & Lookbehind Guide. The guide below explains exactly what it does and how to use it. In the meantime, here are DevLab tools that already work in your browser:
Browse all working tools →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.
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.
When to use Lookahead & Lookbehind Guide
- Validate passwords requiring uppercase, a digit, and a symbol without capturing substrings by stacking multiple lookaheads from position zero.
- Extract numeric prices from mixed-currency strings like '$29.99 or €49' using a lookbehind to strip the symbol before matching digits.
- Debug why an existing lookahead fails silently by isolating each assertion and watching the color-coded match map update in real time.
Frequently Asked Questions
Why does (?<=\d+) throw a SyntaxError in JavaScript when the same pattern works in Python?
Can I stack multiple lookaheads in one pattern, and does their order affect which strings match?
What is a zero-width assertion, and why does nothing from the lookahead appear in the match result?
How do I write a negative lookbehind to match 'px' only when it is not preceded by a digit?
Does this tool show what text the lookbehind itself matched, or only whether the assertion passed?
Related Tools
- Regex Testertest and debug regular expressions with real-time matching · Regex
- Regex Explainerbreak down a regex pattern into plain English with visual diagrams · Regex
- Named Capture Groupslearn and test named capture groups in regex · Regex
- Regex Flags Explainedunderstand what regex flags g, i, m, s, u, y do with live examples · Regex