[New-bugs-announce] [issue15956] backreference to named group does not work

Steve Newcomb report at bugs.python.org
Mon Sep 17 15:33:47 CEST 2012


New submission from Steve Newcomb:

The '\\g<startquote>' in the below does not work:

>>> repr( re.compile( '\\<\\!ENTITY[ \\011\\012\\015]+\\%[ \\011\\012\\015]*(?P<entityName>[A-Za-z][A-Za-z0-9\\.\\-\\_\\:]*)[ \\011\\012\\015]*(?P<startquote>[\\042\\047])(?P<entityText>.+?)\\g<startquote>[ \\011\\012\\015]*\\>', re.IGNORECASE | re.DOTALL).search( '<!ENTITY % m.mixedContent "( #PCDATA | i | b)">'))
'None'

In the following, the '\\g<startquote>' has been replaced by '\\2'.  It works.

>>> repr( re.compile( '\\<\\!ENTITY[ \\011\\012\\015]+\\%[ \\011\\012\\015]*(?P<entityName>[A-Za-z][A-Za-z0-9\\.\\-\\_\\:]*)[ \\011\\012\\015]*(?P<startquote>[\\042\\047])(?P<entityText>.+?)\\2[ \\011\\012\\015]*\\>', re.IGNORECASE | re.DOTALL).search( '<!ENTITY % m.mixedContent "( #PCDATA | i | b)">'))
'<_sre.SRE_Match object at 0x7f77503d1918>'

Either this feature is broken or the re module documentation is somehow misleading me.

(Yes, I know there is an XML error in the above.  That's because it's SGML.)

----------
components: Regular Expressions
messages: 170605
nosy: ezio.melotti, mrabarnett, steve.newcomb
priority: normal
severity: normal
status: open
title: backreference to named group does not work
type: behavior
versions: Python 2.7

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


More information about the New-bugs-announce mailing list