[New-bugs-announce] [issue43714] re.split(), re.sub(): '\Z' must consume end of string if it matched

Alexander Grigoriev report at bugs.python.org
Sat Apr 3 09:03:13 EDT 2021


New submission from Alexander Grigoriev <alegrigoriev at gmail.com>:

If '\Z' matches as part of a pattern in re.sub() or re.split(), it should consume the end of string, and then '\Z' alone should not match the end of string again.

Current behavior:

Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> print(re.split(r'/?\Z', 'a/b/c/d/'))
['a/b/c/d', '', '']
>>> print(re.sub(r'/?\Z', '-', 'a/b/c/d/'))
a/b/c/d--


Wanted behavior:

>>> print(re.split(r'/?\Z', 'a/b/c/d/'))
['a/b/c/d', '']
>>> print(re.sub(r'/?\Z', '-', 'a/b/c/d/'))
a/b/c/d-

----------
components: Library (Lib)
messages: 390124
nosy: alegrigoriev
priority: normal
severity: normal
status: open
title: re.split(), re.sub(): '\Z' must consume end of string if it matched
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43714>
_______________________________________


More information about the New-bugs-announce mailing list