in reply to Not-really variable length lookbehind
You probably thought that (?<=199\d|200\d|\D) (note: the (?:) is useless here) would do something like (?:(?<=199\d)|(?<=200\d)|(?<=\D)), but that is not how it works. In pseudo-code, this is what the regex engine does:
But here, the imaginary matchlength function can't return a single value, because the subregex can match strings of different lengths. So in your case, the engine doesn't know how many characters to go back before trying the look-behind.# (?<=199\d|200\d|\D) sub lookbehind { my $subregex = shift; # qr/199\d|200\d|\D/; local pos() = pos() - matchlength($subregex); return /$subregex/; }
Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).
|
|---|