There are two ways to approach this:
- Figure out the length
N of the lookbehind assertion, and check for it exactly N characters back in the string. This is what Python does. I personally find it slightly restrictive...
2. Allow any expression. Just step back through the string one character at a time and test if the lookbehind matches AND ends right at the previous position. This is obviously very slow but much more flexible. One optimization here could be to calculate the minimum length of the match and start there. Doing the same thing with a max length may not be worth it, since stuff like (?<=a{2,5}) isn't that common.
My idea is to combine both: when the first approach can be used, then use it! When the given regex wouldn't work with it (e.g. (?<=a+)b), then use method 2. Using method 2 in practice utterly failed. Not even Perl allows that. I just went with method 1.
There are two ways to approach this:
Nof the lookbehind assertion, and check for it exactlyNcharacters back in the string. This is what Python does. I personally find it slightly restrictive...2. Allow any expression. Just step back through the string one character at a time and test if the lookbehind matches AND ends right at the previous position. This is obviously very slow but much more flexible. One optimization here could be to calculate the minimum length of the match and start there. Doing the same thing with a max length may not be worth it, since stuff like(?<=a{2,5})isn't that common.My idea is to combine both: when the first approach can be used, then use it! When the given regex wouldn't work with it (e.g.Using method 2 in practice utterly failed. Not even Perl allows that. I just went with method 1.(?<=a+)b), then use method 2.