Sunday, May 02, 2010

Perl does not allow variable length lookbehind. The restriction is easily found when attempting to use a backreference in a lookbehind. Perl's regex compiler is dumb about backreferences though, since some backreferences are a known length at compile time. When this is the case, Perl's error message error is confusing. For instance, you would expect group 1 in

$str =~ /(.)(?<=\1)/

to match a character that is not preceded by itself. In this case, group 1 is always one character long, but the perl regex compiler doesn't know that. It treats it the same as it would

$str =~ /(.+)(?<=\1)/

and gives the same error message.

No comments: