regex (?!..) problem

Wolfgang Rohdewald wolfgang at rohdewald.de
Mon Oct 5 10:58:37 CEST 2009


On Monday 05 October 2009, MRAB wrote:
> "(?!.*?(C1).*?\1)" will succeed only if ".*?(C1).*?\1" has failed,
>  in which case the group (group 1) will be undefined (no capture).

I see. 

I should have moved the (C1) out of this expression anyway:

>>> re.match(r'L(?P<tile>..)(?!.*?(?P=tile).*?(?P=tile))(.*?
(?P=tile))','LC1 C1B1B1B1 b3b3b3b3 C2C2C3').groups()
('C1', ' C1')

this solves my problem, thank you!


-- 
Wolfgang



More information about the Python-list mailing list