[Python-Dev] a feature i'd like to see in python #2: indexing of match objects

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 3 19:59:00 CET 2006


Fredrik Lundh schrieb:
>> Ah, right; I misread his proposal as saying that m[:] should return
>> [m[0]] + list(m.groups()) (rather, I expected that m.groups() would
>> include m.group(0)).
> 
> match groups are numbered 1..N, not 0..(N-1), in both the API and in the 
> RE syntax (and we don't have much control over the latter).

py> m = re.match("a(b)","ab")
py> m.group(0)
'ab'
py> m.group(1)
'b'

>> To answer your first question: it is clearly groups that you want
>> to index, just as the .group() method indexes groups.
> 
> so what should len(m) do?

That's a question: should len be supported at all? If so, it's clear
that len(m) == len(m[:]).

Regards,
Martin


More information about the Python-Dev mailing list