[New-bugs-announce] [issue24580] Wrong or missing exception when compiling regexes with recursive named backreferences

Dan Haffey report at bugs.python.org
Tue Jul 7 03:25:41 CEST 2015


New submission from Dan Haffey:

Error reporting for recursive backreferences in regexes isn't consistent across both types of backref. Here's the exception for a recursive numeric backref:

>>> import re
>>> re.compile(r'(\1)')
Traceback (most recent call last):
    ...
sre_constants.error: cannot refer to an open group at position 1

Here's what I'm seeing on the 3.5 branch for a named backref:

>>> re.compile(r'(?P<spam>(?P=spam))')
Traceback (most recent call last):
    ...
RecursionError: maximum recursion depth exceeded

Which is an improvement over 3.4 and below, where compilation succeeds and appears to treat (?P=spam) as valid but unmatchable.

----------
components: Regular Expressions
messages: 246390
nosy: dhaffey, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: Wrong or missing exception when compiling regexes with recursive named backreferences
type: behavior

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


More information about the New-bugs-announce mailing list