Confused about 'positive lookbehind assertion'

Andrew Durdin adurdin at
Wed Sep 26 00:01:06 CEST 2007

On 9/25/07, Karthik Gurusamy <kar1107 at> wrote:
> Any idea what this positive lookbehind achieves which can't be done
> without it.
> I remember cases where positive look-ahead is useful.
> In the above example,'abcdef') does the job of ensuring
> 'def' is preceded by 'abc'.

AFAICT the only benefit I can see is that the lookbehind isn't
captured, so (a) it's not included in, and (b)
match.start(), match.end(), and match.span() return the offsets of the
bit you actually wanted to capture.

OTOH, I often find the negative lookbehind (?!...) very useful indeed.


More information about the Python-list mailing list