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

Yingjie Lan lanyjie at yahoo.com
Wed Nov 3 02:32:18 EDT 2010



--- On Wed, 11/3/10, John Bond <lists at asd-group.com> 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.

Regards,

Yingjie


--- On Wed, 11/3/10, John Bond <lists at asd-group.com> wrote:

> From: John Bond <lists at asd-group.com>
> Subject: Re: Must be a bug in the re module [was: Why this result with the re module]
> To: python-list at python.org
> Date: Wednesday, November 3, 2010, 8:43 AM
> On 3/11/2010 4:23 AM, Yingjie Lan
> wrote:
> > --- On Wed, 11/3/10, MRAB<python at mrabarnett.plus.com> wrote:
> >
> >> From: MRAB<python at mrabarnett.plus.com>
> >> Subject: Re: Must be a bug in the re module [was:
> Why this result with the re module]
> >> To: python-list at python.org
> >> Date: Wednesday, November 3, 2010, 8:02 AM
> >> On 03/11/2010 03:42, Yingjie Lan
> >> wrote:
> >> Therefore the outer (first) group is always an
> empty string
> >> and the
> >> inner (second) group is the same as the previous
> example
> >> (the last
> >> capture or '' if no capture).
> > Now I am confused also:
> >
> > If the outer group \1 is empty, how could the inner
> > group \2 actually have something?
> >
> > Yingjie
> >
> >
> >
> 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. I
> 
> If you took away the outer groups repetition:
> 
> re.findall('((.a.)*)', 'Mary has a lamb')
> 
> then, for each of the six matches, it returns the full
> thing that was 
> matched:
> 
> ('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'),
> ('', ''), ('', 
> '')]
> 
> Cheers, JB
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


      



More information about the Python-list mailing list