Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Why is variable length lookahead implemented while lookbehind is not?

by halley (Prior)
on Sep 07, 2011 at 19:40 UTC ( #924647=note: print w/replies, xml ) Need Help??

in reply to Why is variable length lookahead implemented while lookbehind is not?

Having never looked at Perl's C implementation of this, I think it's just a matter of not writing support for it, because it is "touchy" code after so many minor tweaks, and supporting both directions may need yet more maintenance.

Theoretically, any regular expression can be processed in reverse; that is, when searching for /def$/, you can look backwards through the string for the end of a line, then for an 'f' before it, then for an 'e' before that, and so on. This holds true no matter what the complexity of the pattern may be.

In practice, there's a lot about a regex matcher engine that must be written with an expectation of the direction you're walking through the pattern and the source string. Parameterizing the direction or stride as +1/-1 is perhaps not trivial. So they punted: simple strings with an obvious anchor (current spot, end of line, etc.) can appear to be scanned backwards by calculating where they would start and scanning forwards.

[ e d @ h a l l e y . c c ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://924647]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-09-18 21:22 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (113 votes). Check out past polls.