I still don't seem to be able to get negative lookbehind. I have a situation where I want to be able to match all lines that have a certain string in them, iff they don't have a certain other string anywhere before it. I want to be able to find all lines that occur w/"_view" that do not have "ora" behind them. So "blahblahorablahblah_view" should not match, but "blahblah_view" should. I've tried mating (?<!ora)
with _view
but it always hits on something w/that has anything that isn't "ora" before "_view". [^(ora)]
also doesn't seem to get me what I want.
I also tried learning from Perl: Matching string not containing PATTERN but that didn't get me anywhere. (It doesn't seem to mix positive and negative matches the way I want)
I'm also using https://regex101.com understanding that it is a robust and general tool for diagnosing regexes.
I'm not using Perl or Java but an IDE (PhpStorm), so what ever applies to grep
should be good enough.
At least two ways are possible:
The one that uses lookarounds:
^(?!.*ora.*_view).*_view.*
(easy to write but not efficient, because it may cause a lot of backtracking)
The one that uses negated character classes:
^[^o_]*(?:o(?!ra)[^o_]*|_(?!view)[^o_]*)*_view.*
or the version with possessive quantifiers (if available):
^[^o_]*+(?:o(?!ra)[^o_]*|_(?!view)[^o_]*)*+_view.*
or the version that emulates possessive quantifiers (if not available):
^(?=([^o_]*))\1(?=((?:o(?!ra)[^o_]*|_(?!view)[^o_]*)*))\2_view.*
Except if your IDE uses the .net regex engine (that allows variable length lookbehinds) or at least the Java regex engine (that allows limited variable length lookbehinds), there's no way to use a lookbehind here.