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

MRAB python at
Wed Nov 3 18:59:35 CET 2010

On 03/11/2010 06:32, Yingjie Lan wrote:
> --- On Wed, 11/3/10, John Bond<lists at>  wrote:
>> I just explained that (I think!)! The outer capturing group
>> uses
>> repetition, so it returns the last thing that was matched
>> by the inner
>> group, which was an empty string.
> According to yourself, the last match of the
> inner group is also empty!
> Generally speaking,
> as a match for the outer group always
> contains some matches for the inner group,
> it must be the case that the last match
> for the inner group must be contained
> inside the last match of the outer group.
> So if the last match of the
> outer group is empty, then the last
> match for the inner group must
> also be empty.
The outer group is repeated, so it can match again, but the inner group
can't match again because it captured all it could the previous time.

Therefore the outer group matches and captures an empty string and the
inner group remembers its last capture.

More information about the Python-list mailing list