Regexdrill

Level 5: Advanced Exercise 73 of 88 Free

Negative lookahead: lines without a word

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

The whole line must match. Match every line that does not contain the lowercase text error anywhere in it.

What this exercise teaches

(?!.*error).* first checks, without moving, that no error follows anywhere on the line, and only then matches the line. A negated class like [^error] does something else: it rejects single letters, not the word.

A hint if you get stuck

A negative lookahead at the start can scan the whole line: (?!.*error) fails if error appears anywhere ahead. After it, match the line itself with .*

Try it now, free, no account needed

Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. The worked solution opens once you solve it or after two tries.

Open this exercise

More exercises in Advanced