You want to match complete lines that do not contain the word
|Regex options: Case insensitive, ^ and $ match at line breaks (“dot matches line breaks” must not be set)|
In order to match a line that does not contain something, use negative lookahead
(described in Recipe 2.16). Notice that in
this regular expression, a negative lookahead and a dot are repeated
together using a noncapturing group. This makes sure that the regex
\bninja\b› fails at
every position in the line. The ‹
^› and ‹
$› anchors are placed at the edges of the
regular expression to make sure you match a complete line.
The options you apply to this regular expression determine
whether it tries to match the entire subject string or just one line
at a time. With the option to let ‹
^› and ‹
$› match at line breaks enabled and the option
to let dot match line breaks disabled, this regular expression works
as described and matches line by line. If you invert the state of
these two options, the regular expression will match any string that
does not contain the word “ninja”.
Testing a negative lookahead against every position in a line or string is rather inefficient. This solution is only intended to be used in situations where one regular expression is all that can be used, such as when using an application that can’t be programmed. When programming, ...