This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Behavior of backreferences to named groups in regular expressions unclear
Type: enhancement Stage:
Components: Documentation Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: aresnick, georg.brandl, jimjjewett
Priority: low Keywords: patch

Created on 2009-01-08 15:35 by aresnick, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
re-backreference-clarification.patch aresnick, 2009-02-10 17:50
Messages (5)
msg79417 - (view) Author: alec resnick (aresnick) Date: 2009-01-08 15:35
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 and
the description of the (?P<name>) behavior at 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.
msg79525 - (view) Author: Jim Jewett (jimjjewett) Date: 2009-01-10 03:02
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.)
msg80100 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-01-18 13:51
I'm happy to review such a patch.
msg81568 - (view) Author: alec resnick (aresnick) Date: 2009-02-10 17:50
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.


msg84863 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 19:07
Committed a similar patch in r70866.
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49132
2009-03-31 19:07:20georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg84863
2009-02-10 17:50:58aresnicksetfiles: + re-backreference-clarification.patch
keywords: + patch
messages: + msg81568
2009-01-18 13:51:34georg.brandlsetpriority: low
messages: + msg80100
2009-01-10 03:02:04jimjjewettsetnosy: + jimjjewett
messages: + msg79525
2009-01-08 15:35:46aresnickcreate