Why this result with the re module

Yingjie Lan lanyjie at yahoo.com
Tue Nov 2 08:05:19 CET 2010


> From: John Bond <lists at asd-group.com>
> >>>> re.findall('(.a.)+', 'Mary has a lamb')
> > ['Mar', 'lam']

> It's because you're using capturing groups, and because of
> how they work - specifically they only return the LAST match
> if used with repetition (and multiple matches occur).

It seems capturing groups is assumed by default,
but this is somehow against my intuition...
Ituitively, it should be what matches the 
whole regex '(.a.)+', shouldn't it?

Regards,

Yingjie


      



More information about the Python-list mailing list