Confused about 'positive lookbehind assertion'
adurdin at gmail.com
Wed Sep 26 00:01:06 CEST 2007
On 9/25/07, Karthik Gurusamy <kar1107 at gmail.com> 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, r.search('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 match.group(n), 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