[issue15956] backreference to named group does not work

Amaury Forgeot d'Arc report at bugs.python.org
Tue Sep 18 09:42:47 CEST 2012


Amaury Forgeot d'Arc added the comment:

> And why isn't \g<groupname> part of the pattern language, anyway, or at
> least some way to refer to a match made in a previous *named* group?

But this way exists: (?P=startquote) is what you want.  To me \g is an exception, and frankly I did not know about it before this bug report.


I agree that the following sentence could be better structured:
"""
For example, if the pattern is (?P<id>[a-zA-Z_]\w*), the group can be referenced by its name in arguments to methods of match objects, such as m.group('id') or m.end('id'), and also by name in the regular expression itself (using (?P=id)) and replacement text given to .sub() (using \g<id>).
"""

It probably needs to be split into several pieces, contributions are welcome.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15956>
_______________________________________


More information about the Python-bugs-list mailing list