cedric briner wrote:
> Hello,
> 
> I do not understand the behaviour of this:
> 
> import re
> re.search('(a)*','aaa').groups()
> ('a',)
> 
> I was thinking that the ``*'' will operate on the group delimited by the 
> parenthesis. And so, I was expecting this result:
> ('a', 'a', 'a')
> 
> Is there something I'am missing ?

It just doesn't work that way. The returned group is the last string 
matched by the group:
In [17]: re.search('(a.)*','azabac').groups()
Out[17]: ('ac',)

Use re.findall() instead:
In [18]: re.findall('a.', 'azabac')
Out[18]: ['az', 'ab', 'ac']

If you want overlapping matches you have to search in a loop and collect 
them yourself, findall() gives only non-overlapping matches.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to