I was always under the impression that you couldn\'t use repetition quantifiers in zero-width assertions (Perl Compatible Regular Expressions [PCRE]). However, it has recent
Regex engines are designed to work from left to right.
For lookaheads, the engine matches the entire text at the right of current position. However, for lookbehinds, the regex engine determines the length of string to step back and then checks for the match (again left to right).
So, if you provide some infinite quantifiers like * or +, lookbehind wont work because the engine does not know how many steps to go backward.
I'll give an example of how lookbehind works (the example is pretty silly though).
Suppose you want to match the last name Panta, only if the first name is 5-7 characters long.
Let's take the string:
Full name is Subigya Panta.
Consider the regex:
(?<=\b\w{5,7}\b)\sPanta
The engine acknowledges the existence of a positive lookbehind and so it first searches for the word Panta (with a whitespace character before it). It is a match.
Now, the engine looks to match the regex inside the lookbehind. It steps backward 7 characters (as the quantifier is greedy). The word boundary matches the position between space and S. Then it matches all the 7 characters, and then the next word boundary matches the position between a and the space.
The regex inside the lookbehind is a match and thus the whole regex returns true because the matched string contains Panta. (Note that lookaround assertions are zero-width, and do not consume any characters.)