I am attempting to grep for all instances of Ui\.
not followed by Line
or even just the letter L
What is the proper way to write a regex for finding all instances of a particular string NOT followed by another string?
Using lookaheads
grep "Ui\.(?!L)" *
bash: !L: event not found
grep "Ui\.(?!(Line))" *
nothing
Negative lookahead, which is what you're after, requires a more powerful tool than the standard grep
. You need a PCRE-enabled grep.
If you have GNU grep
, the current version supports options -P
or --perl-regexp
and you can then use the regex you wanted.
If you don't have (a sufficiently recent version of) GNU grep
, then consider getting ack
.