regexmissing-symbols

Have Regex Find Absent Word


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?


Solution

  • 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"
    )