sre negated lookaheads/behinds

Robin Becker robin at jessikat.fsnet.co.uk
Wed Oct 18 09:29:14 EDT 2000


I think the documentation is unclear/wrong about how look behinds etc
work.

wpat = re.compile(r'(?<!self\.)\b([A-Za-z_]\w*)\s*\(')

fails for 

wpat.search('   a(')

and succeeds for 

wpat.search('      a(')


I guess because internally the matcher is using the negated positive
look behind.

Clearly my a( is not preceded by self. in either case. However, in the
first case as there is not enough room for the positive look behind I
think it is wrongly failing to match. Is this correct?

I know the documentation mentions that the (?< ... ) patterns must be
fixed length, but nowhere does it say that negated patterns must be
fixed length.
-- 
Robin Becker



More information about the Python-list mailing list