[New-bugs-announce] [issue32308] Replace empty matches adjacent to a previous non-empty match in re.sub()
report at bugs.python.org
Wed Dec 13 13:28:38 EST 2017
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
Currently re.sub() replaces empty matches only when not adjacent to a previous match. This makes it inconsistent with re.findall() and re.finditer() which finds empty matches adjacent to a previous non-empty match and with other RE engines.
Proposed PR makes all functions that makes repeated searching (re.split(), re.sub(), re.findall(), re.finditer()) mutually consistent.
The PR change the behavior of re.split() too, but this doesn't matter, since it already is different from the 3.6 behavior.
BDFL have approved this change.
This change doesn't break any stdlib code. It is expected that it will not break much third-party code, and even if it will break some code, it can be easily rewritten. For example replacing re.sub('(.*)', ...) (which now matches an empty string at the end of the string) with re.sub('(.+)', ...) is an obvious fix.
components: Library (Lib), Regular Expressions
nosy: ezio.melotti, mrabarnett, serhiy.storchaka
title: Replace empty matches adjacent to a previous non-empty match in re.sub()
versions: Python 3.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce