> From: John Bond <li...@asd-group.com>
> Subject: Re: Why this result with the re module
> >>>> re.findall('(.a.)*', 'Mary has a lamb')
> > ['Mar', '', '', 'lam', '', '']

> So - see if you can explain the first "problematic" result
> now.

Thanks a lot for explaining to me the second "problematic" result!
But the first one is even more puzzling...mainly because the
pattern matches any empty string. Here are more examples:

>>> re.findall('(.a.)*','')
['']
>>> re.findall('(.a.)*',' ') #one space
['', '']
>>> re.findall('(.a.)*','  ') #two spaces
['', '', '']
>>> len(re.findall('(.a.)*',' '*4)) #four
5
>>> len(re.findall('(.a.)*',' '*8)) #eight
9

I must need more details of the matching algorithm to explain this?

Regards,

Yingjie



      
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to