Locate line that starts with negation of the expression

Asked

Viewed 167 times

5

I have a text file with many lines. It is possible for me to find the first line that does not match the regex? Example, I want to make a regex that shows me the first line that doesn’t start with BOLO

CAKE
CAKE
CHOCOLATE

I’m using the sublime, namely, my regex have to find the word CHOCOLATE. Remembering that my regex needs to be on top of the word CAKE because I don’t know which line comes after.

1 answer

5


Combine the anchor (^) starting with the negative lookhead (?!) this will identify lines that do not start with CAKE

^(?!BOLO)

Text:

BOLO
BOLO
CHOCOLATE
RECEITAS BOLO

This example houses the last two lines.

See working on REGEX101

  • Thanks, it worked out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.