I currently have a regular expression to match where a string contains 'bar' but is not preceded by 'foo':
(?<!foo)bar
I wish to modify the regex to match where a string contains 'bar' but is not preceded by 'foo' and (optionally) any additional character(s).
EG. 'footestbar' should not match as bar is preceded by 'foo' followed by 'test'.
I cannot find a way to achieve this as regular expressions do not permit the use of a quantifier within a negative lookbehind. Subsequently I cannot do the following:
(?<!foo.*)bar
Is there an alternative approach?
UPDATE:
The regular expression flavour is re2. I am currently reviewing the documentation, but on first glance have noticed the following:
(?<!re) after text not matching re (NOT SUPPORTED)
Therefore the solution cannot use a negative lookbehind (if I'm interpreting the documentation correctly).


I've just read that after text not matching is not supported:
– Fitzroy Feb 01 '16 at 12:01