Regex: match strings that don't match the submode

Let's say I have a regex foobar expression, and I want to find all the lines in the document that do not match foobar. I can do it? How can I do it?

+4
source share
2 answers
^(?!.*foobar.*).+$ 

With a multi-line option, matches an entire line that does not contain foobar.

+11
source

The regular expression for your case might be this

 ^((?!foobar))$ 

edited by:

but if you want only grep then you can use the -v option:

 grep -v foobar 
0
source

Source: https://habr.com/ru/post/1346776/


All Articles