I don't understand this regex.groups() behaviour

Grzegorz Adam Hankiewicz gradha at titanium.sabren.com
Sat Jun 14 07:06:35 EDT 2003


On 2003-06-13, Fredrik Lundh <fredrik at pythonware.com> wrote:
> > I don't understand why the last two sentences of the following
> > interactive session don't return more than two groups.
> 
> because there are only two group markers in your expression,
> of course.
> 
> if you want multiple matches, use findall.

Well, I don't want multiple matches, I want one match that returns N
groups. If you try to use findall with THAT regular expression still
only two tuples are returned, because the regular expression states
explicitly that the end group must be at the end of the string.

I can create a regular expression with N groups being only the last
one ending with newline, but that's not very useful if I don't know
how many groups there are.

-- 
 Please don't send me private copies of your public answers. Thanks.





More information about the Python-list mailing list