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
Internal error when compile RE with conditional expression referring to not defined group #91700
When compile a regular expression with conditional expression which refers to not defined group (i.e. refers by group number which larger than the number of captured groups) you get an internal error:
>>> re.compile('()(?(2)a)')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/re/__init__.py", line 225, in compile
return _compile(pattern, flags)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/serhiy/py/cpython/Lib/re/__init__.py", line 273, in _compile
p = _compiler.compile(pattern, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/serhiy/py/cpython/Lib/re/_compiler.py", line 836, in compile
return _sre.compile(
^^^^^^^^^^^^^
RuntimeError: invalid SRE code
Referring to groups which are defined after the conditional expression is allowed. There are special tests for this. It means that we cannot just compare the reference number with the number of groups defined before it.
Activity
pythongh-91700: Validate the group number in conditional expression i…
gh-91700: Validate the group number in conditional expression in RE (G…
[3.10] pythongh-91700: Validate the group number in conditional expre…
[3.10] gh-91700: Validate the group number in conditional expression …
[3.10] pythongh-91700: Validate the group number in conditional expre…
[3.9] gh-91700: Validate the group number in conditional expression i…
[3.9] pythongh-91700: Validate the group number in conditional expres…