Must be a bug in the re module [was: Why this result with the re module]

John Bond lists at asd-group.com
Wed Nov 3 00:33:15 EDT 2010


> OK, I've got that, and I have no problem with the capturing part.
> My real problem is with the number of total matches.
> *I think it should be 4 matches in total but findall
> gives 6 matches*, for the new regex '((.a.)*)*'.
> I'd love to know what you think about this.
>
> Many thanks!
> Yingjie
>
>
>
>
We've already been through that, and nothing's changed - all you've done is:

1) taken something that you know (now!) has six matches:

(.a.)*

2) added an outer capturing group (which does not change the actual 
matches, only what gets returned):

((.a.)*)

3) then said there must be >=0 occurrences of what's inside it, which of 
course there is, so that has no effect.

((.a.)*)*

End result: the matching is exactly the same, findall still needs to 
return the 6 things it did in the first place, but now it also has to 
return an extra value at each return location (that being what's 
captured by the new outer group) hence the tuples.

Cheers, JB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101103/d82ac5c7/attachment.html>


More information about the Python-list mailing list