You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Behavior of backreferences to named groups in regular expressions unclear #49132
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/birkenfeld'closed_at=<Date2009-03-31.19:07:20.189>created_at=<Date2009-01-08.15:35:46.076>labels= ['type-feature', 'docs']
title='Behavior of backreferences to named groups in regular expressions unclear'updated_at=<Date2009-03-31.19:07:20.188>user='https://bugs.python.org/aresnick'
I recently learned about named groups in Python regular expressions.
Almost all the documentation I've found online explains what they are
and give a simple example of how to use them. I was trying to use the
variables outside of the original regex, later in the code. Nowhere in
the documentation I found after a couple hours of searching was it
mentioned that named groups can only be backreferenced _within_ the pattern.
Sorry to be so long in getting back to you. I've attached a suggested
patch for the python-2.6.1-docs-text/library/re.txt documentation.
Also, in looking over Kuchling's HOWTO, the necessary information is
actually there, and I just wasn't paying attention =) Let me know if
I should do something else--this is my first 'fix'/submission to
Python, and I'm eager for feedback.
Activity
aresnick commentedon Jan 8, 2009
I recently learned about named groups in Python regular expressions.
Almost all the documentation I've found online explains what they are
and give a simple example of how to use them. I was trying to use the
variables outside of the original regex, later in the code. Nowhere in
the documentation I found after a couple hours of searching was it
mentioned that named groups can only be backreferenced _within_ the pattern.
In particular, the sections at
http://www.amk.ca/python/howto/regex/#SECTION000530000000000000000 and
the description of the (?P<name>) behavior at
http://docs.python.org/library/re.html could be modified to make it
clear that the named capture does not create a variable usable outside
of the pattern.
I would be happy to alter the documentation appropriately.
jimjjewett commentedon Jan 10, 2009
That sounds like a good idea, particularly since it is a bit different
from Perl. Please do write up the a clarification.
Typically, I have either attached a file with the suggested wording, or
included it in a comment from which a commiter could cut-and-paste.
(If Georg has different preferences on how to submit the patch, they
should probably go into a FAQ anyhow.)
birkenfeld commentedon Jan 18, 2009
I'm happy to review such a patch.
aresnick commentedon Feb 10, 2009
Hi Georg!
Sorry to be so long in getting back to you. I've attached a suggested
patch for the python-2.6.1-docs-text/library/re.txt documentation.
Also, in looking over Kuchling's HOWTO, the necessary information is
actually there, and I just wasn't paying attention =) Let me know if
I should do something else--this is my first 'fix'/submission to
Python, and I'm eager for feedback.
Thanks!
Gratefully,
a.
birkenfeld commentedon Mar 31, 2009
Committed a similar patch in r70866.