-2

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?

eklisiarh
  • 145
  • 8

1 Answers1

-1

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"
)
Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
  • Thank you for that, especially for the explanation. Since my @ something words are all different (@ book, @ article and so on) for some reason this reges was marking all those words so I removed \w from it and this worked! – eklisiarh Jul 06 '20 at 06:43
  • \w means `[A-Za-z0-9_]`; so every ASCII word(except `unicode flag is used`) comes there @eklisiarh; Why you have to remove it? –  Jul 06 '20 at 06:46
  • @mandy: because it was showing every entry in my bibliography. No idea why. – eklisiarh Jul 06 '20 at 18:14