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
The pcrepattern man page documents the restriction that lookbehind assertions must be either be fixed-width, or be several fixed width patterns separated by |'s, and then explains that this is because:
The implementation of lookbehind assertions is, for each alternative, to temporarily move the current position back by the fixed length and then try to match. If there are insufficient characters before the current position, the assertion fails.
I'm not sure why they do it this way, but my guess is that they spent a lot of time writing a good backtracking RE-matching engine that runs forward, and they didn't want to duplicate all that effort to write another that runs backwards. The obvious approach would be to run over the string backwards -- that's easy -- while matching a "reverse" version of your lookbehind assertion. Reversing a "real" (DFA-matchable) RE is possible -- the reverse of a regular language is a regular language -- but PCRE's "extended" RE's are IIRC turing complete, and it may not even be possible to flip one around to run backwards efficiently in general. And even if it were, probably no-one has actually cared enough to bother. After all, lookbehind assertions are a pretty minor feature in the grand scheme of things.