Negative Lookbehind (?<!)
Negative lookbehind matches when a pattern is NOT preceded by something specific.
Syntax
(?<!lookbehind)pattern matches "pattern" only if NOT preceded by "lookbehind".
Matches numbers NOT preceded by "$".
Exercises
Practical Examples
Combining All Lookarounds
All Four Lookarounds Summary
| Lookaround | Syntax | Meaning |
|---|---|---|
| Positive Lookahead | (?=...) | Followed by |
| Negative Lookahead | (?!...) | NOT followed by |
| Positive Lookbehind | (?<=...) | Preceded by |
| Negative Lookbehind | (?<!...) | NOT preceded by |
Complex Example
Practice Playground
Try:
(?<!\$)\d+- numbers without $(?<![a-z])\d+- numbers not after letters(?<!#)\w+- words not after #(?<!\\)"- unescaped quotes
Key Takeaways
(?<!pattern)is a negative lookbehind- Matches only when NOT preceded by the pattern
- Combine with other lookarounds for complex matching
- Useful for excluding prefixed patterns
- All lookarounds are zero-width assertions

