Why not match.expand('\\0')?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Sat Dec 13 17:08:58 EST 2003


In article <mailman.120.1071315843.9307.python-list at python.org>,
Fredrik Lundh wrote:
>Magnus Lie Hetland wrote:
>
[snip]
>because there is no group 0; the m.group(0) call is just a shortcut
>to get the entire match.
>
>(try m.groups() if you don't believe me)

Hehe. I believe you -- and I know how this behaves. I guess I'm
questioning the behavior. You say "there is no group 0", while I say
"why isn't group 0 in m.groups(), m.groupdict() and so on?"

In other words, I see "group 0" as a name for the entire match, just
as m.group(0) is a shortcut to it. It clearly exists, in some sense,
but whether it is actually a group or not -- well, I'm quite sure you
are right in the matter. (IIRC, other languages such as AWK don't
treat this as a "short-cut", but as a real group in its own right...
But I may not RC :)

I guess I just think it would be useful to extend the "shortcut" of
the "group" 0 to more than just the group method. There are (IMO)
cases where referencing the entire match (e.g.  as '\\0') can be
useful. Of course one can add an extra set of parentheses, but in my
case that's not really feasible.

As it is, I have simply written a wrapper function to deal with the
special case. But I was pretty confused about my unit test output for
a while there...

></F>

-- 
Magnus Lie Hetland           "The mind is not a vessel to be filled,
http://hetland.org            but a fire to be lighted."  [Plutarch]




More information about the Python-list mailing list