How do I get to *all* of the groups of an re search?

Kyler Laird Kyler at news.Lairds.org
Sat Jan 11 18:26:02 EST 2003


Tim Peters <tim.one at comcast.net> writes:

>>> and would also (at least) complicate the meaning of backreferences
>>> (what is \1 >supposed to match then?  "a list" of all strings ever
>>> matched by group 1?

>> Yes, that is what I have suggested.

>I don't think so.  You expected that .group(n) would return a list of all
>substrings matched by group n, but that's a different question than what the
>regular expression component \n should match.

Yes, I'm sorry.  I was simply thinking of them being the same.
I agree that such a practice would render \1 useless in the RE.

>>> Sure.  For example, finding the last component of a path expression,
>>> in>order to isolate the file name, is a common application.

>> That's readily done using simple REs without depending on this
>> behavior.

>Of course, but what of it?

I would chose a method that does not rely on arbitrary
implementation-specific decisions.  Those methods are readily
available.

>As you replied to another poster who pointed out
>that there are other ways to do what you want, you don't care, you want what
>you want.

No, I want what is documented.  I want what would seem obvious
to someone who has not been tainted by experience with other
languages.

Failing that, I'd like all documentation of Python to be
correct on its own.

>> They won't have the experience to look at a piece of Python
>> documentation and say "Oh, but surely they don't mean *that*."

>If they also have the humility to read all the docs before presuming they
>understand any of it, no problem -- it's documented multiple times.  If you
>actually write docs for newbies, you'll know that newbies also space out
>easily when too much info is presented.  Repeating all relevant pieces of
>info at every point isn't friendly to newbies either.

I'm not asking for everything to be repeated.  I just want the
incorrect stuff deleted.

--kyler




More information about the Python-list mailing list