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

Grzegorz Adam Hankiewicz gradha at titanium.sabren.com
Fri Jun 13 20:34:30 CEST 2003


Hi.

I don't understand why the last two sentences of the following
interactive session don't return more than two groups.

Python 2.2.3 (#1, Jun  5 2003, 14:02:17)
Type "copyright", "credits" or "license" for more information.

In [1]: import re

In [2]: c = '"A";"AA";"AAA";"AAAA";"AAAAA"'

In [3]: re.match(r'("A+?";)("A+?"$)', c)

In [4]: re.match(r'("A+?";)+("A+?"$)', c).groups()
Out[4]: ('"AAAA";', '"AAAAA"')

In [5]: re.match(r'("A+?";){4}("A+?"$)', c).groups()
Out[5]: ('"AAAA";', '"AAAAA"')

Could somebody please explain why multiple groups aren't returned?

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





More information about the Python-list mailing list