Have Regex Find Absent Word

53 Views Asked by At

I need to find entries which begin with @ and don't have word "keyword" before the next @ within this example:

@something
something
something
keyword
something
something

@something
something
something
something
something

@something
something
something
keyword
something
something

So this search string would point me to the second example. Does someone know how to do this with Regex?

1

There are 1 best solutions below

3
Tim Biegeleisen On BEST ANSWER

The following regex seems to be working:

@\w+(?![^@]*\bkeyword\b[^@]*)

Demo

Explanation:

@\w+             match a @label
(?!              provided that we DON'T see ahead
    [^@]*        any text without another @label
    \bkeyword\b  which also has the "keyword"
)