in reply to Why is variable length lookahead implemented while lookbehind is not?
In Important Notes About Lookbehind, Jan Goyvaerts explains it this way:
The bad news is that most regex flavors do not allow you to use just any regex inside a lookbehind, because they cannot apply a regular expression backwards. Therefore, the regular expression engine needs to be able to figure out how many steps to step back before checking the lookbehind.
In modern versions of Perl, variable-length look-behind is effectively supported using the \K pattern ("K" for "keep"). See perlre.
#!perl use strict; use warnings; use feature qw( say ); my $string = 'aaaabcccc'; $string =~ s/a+\Kb(?=c+)/B/; say $string; __END__ aaaaBcccc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is variable length lookahead implemented while lookbehind is not?
by AnomalousMonk (Archbishop) on Sep 07, 2011 at 20:25 UTC |