Positive Lookahead (?=)
Lookaheads check what comes AFTER a position without including it in the match. They're "zero-width assertions" - they don't consume characters.
Syntax
pattern(?=lookahead) matches "pattern" only if followed by "lookahead".
Matches numbers only when followed by " dollars" - but " dollars" isn't part of the match!
Understanding Zero-Width
The key concept: lookaheads check without consuming.
Only the first "foo" matches because only it's followed by "bar". Notice "bar" isn't highlighted - it's not part of the match.
Exercises
Multiple Conditions
You can chain lookaheads for multiple conditions:
This checks that the string contains both uppercase AND digits.
Practical Examples
Lookahead at Word Boundaries
Practice Playground
Try:
\d+(?= dollars)- amounts in dollars\w+(?= \d)- words before numbers(?=.*dollars).*- lines containing "dollars"
Key Takeaways
(?=pattern)is a positive lookahead- It checks what follows WITHOUT including it in the match
- Zero-width: doesn't consume characters
- Can chain multiple lookaheads for AND logic
- Useful for conditional matching

