sre negated lookaheads/behinds

Andrew Kuchling akuchlin at mems-exchange.org
Thu Oct 19 11:01:15 EDT 2000


Robin Becker <robin at jessikat.fsnet.co.uk> writes:
> Anyhow as for the documentation my intention was to make clear that
> negated patterns are in general variable length ie they match anything
> that doesn't match the given pattern. I suppose it's an implementation
> issue why the condition patterns have to be fixed length or is it some
> restriction on the re language?

Lookaheads can be variable length, because they start at the current
location and go forward, but lookbehinds have to *end* exactly at the
current location, and this is hard.  (?<=a*)b, for example, would be
really inefficient to check, because the regex engine would have to
backtrack all the way to the beginning of the string.  Optimizing this
seems really hard -- if you had a regex engine that could match both
forwards and backwards, and a function that mapped a regex to a regex
that matched the same language, only reverse, then it could be done
fairly efficiently.  But at least the former task is difficult, so
both the Perl and Python engine punt on the fully general version of
the problem and decree that lookbehinds must be of fixed length.

> As for sourceforge I can't seem to get access to login right now. Any
> one else having trouble?

Yes, they seem to be have Web server or database problems at the
moment.  CVS worked this morning, though, at least when I updated my
Python tree.

--amk



More information about the Python-list mailing list