I would like to learn how the regex engine works to disallow a variable lenght lookbehind for the below described technique. This is commonly used to create patterns that has a specific word but mustn't have a previous one.
For example, in this post: RegEx that matches a word that NOT succeeds another one the idea is to match the word cube, only if the word small is not present in the previous 20 character.
So, the answer provided by anubhava to this question was:
.*?small.{0,20}cube|(.*?cube)
And his comment was:
Actually this is simple technique to circumvent the regex engine's capabilities to disallow variable length lookbehind. In this regex we match whatever we don't need using pipe (OR) construct on left hand side and finally leave the right most match in the pipe using a captured group.
I think this technique is very useful but don't know how to use it. I would like to understand how the regex engine works to create this kind of regex. Can anybody give me a hand on this explaining me that?
BTW, don't know if this techinique works in all regex engines, so I've labeled the question with java since I'll use it mainly on it.