17 chars · 1 line
8 chars · 1 line
17 chars · 1 line
8 chars · 1 line
Regex lookahead behavior
Negative lookahead (?!...) rejects a candidate match when the unwanted following pattern is present. In the sample, foo inside foobar is excluded while foo in fooqux and the standalone foo are still returned. This tool is free to use. No account or payment is required.
Last updated
Like positive lookahead, negative lookahead is zero-width. It checks the upcoming text at the current position and either allows or rejects the candidate match without adding the asserted text to the result.
Match foo except when bar follows immediately.
foo(?!bar) / g
foobar fooqux foofoo at index 7
foo at index 14Common questions
No. It only checks whether bar starts at the current position after foo.
A negative character class excludes individual characters, while negative lookahead can reject a multi-character pattern or more complex condition.
Yes, provided the overall JavaScript regex remains valid and the resulting behavior is tested against representative inputs.
Debugging a specific Regex issue? Browse Regex troubleshooting.