in reply to Re: Why is variable length lookahead implemented while lookbehind is not?
in thread Why is variable length lookahead implemented while lookbehind is not?
When you write a backtracking regex engine like the one in Perl 5, a full (variable length) look-ahead is pretty easy to implement.
It seems to me that the easy solution would produce bad performance. The easy solution requires matching each lookbehind subpattern at pos $current_pos - $max_match_length, which is 0 if /.*/ is used!
'bbbbbb' =~ /(?<=[^z]*a)b/
requires checking for "z" and "a" a total of 72 times each before failing even though the string is only 6 chars long!
Oops, I guess you covered this at the end, but it seems to me that it's a foremost concern.
It also forces
to produce'xiyjykz' =~ /(?<=x(.*)y(.*))z/s
but one might expect$1 = 'iyj'; $2 = 'k'
$1 = 'i'; $2 = 'jyk'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Why is variable length lookahead implemented while lookbehind is not?
by moritz (Cardinal) on Sep 07, 2011 at 20:56 UTC | |
|
Re^3: Why is variable length lookahead implemented while lookbehind is not?
by GrandFather (Saint) on Sep 07, 2011 at 20:42 UTC | |
by CountZero (Bishop) on Sep 07, 2011 at 21:11 UTC | |
by ikegami (Patriarch) on Sep 07, 2011 at 20:51 UTC |