You think about it right. But unfortunately, lookbehind usually have a fixed length. The only major exception is the .NET regex mechanism, which allows repeat quantizers inside lookbehinds. But since you only need a negative look, not a look. There is a hack for you. Cancel the line, then try matching:
/rab(?!.{0,10}oof)/
Then change the result of the match or subtract the match position from the length of the string if that is what you are after.
Now, from the regex that you specified, I suggest that this was just a simplified version of what you really need. Of course, if bar is a complex pattern, another thought should decide how to cancel it correctly.
Note that if your template requires both variable and variable-length lookaheads, it will be harder for you to solve this. In addition, in your case it will be possible to deconstruct your lookbehind into several variable lengths (because you are not using either + or * ):
/(?<!foo)(?<!foo.)(?<!foo.{2})(?<!foo.{3})(?<!foo.{4})(?<!foo.{5})(?<!foo.{6})(?<!foo.{7})(?<!foo.{8})(?<!foo.{9})(?<!foo.{10})bar/
But thatβs not all that nice, is it?
Martin ender
source share