https://github.com/python/cpython/commit/e3cc4008c4d73d100fcc0c69f57f925c7470d8d7
commit: e3cc4008c4d73d100fcc0c69f57f925c7470d8d7
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-05-19T16:49:46+03:00
summary:

[3.14] gh-122055: Clarify documentation for empty matches in RE (GH-133169) 
(GH-134217)

(cherry picked from commit 44b73d3cd4466e148460883acf4494124eae8c91)

Co-authored-by: Serhiy Storchaka <storch...@gmail.com>

files:
M Doc/library/re.rst

diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index eb3b1e5549cc98..75ebbf11c8e47c 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -991,8 +991,8 @@ Functions
    That way, separator components are always found at the same relative
    indices within the result list.
 
-   Empty matches for the pattern split the string only when not adjacent
-   to a previous empty match.
+   Adjacent empty matches are not possible, but an empty match can occur
+   immediately after a non-empty match.
 
    .. code:: pycon
 
@@ -1095,9 +1095,12 @@ Functions
 
    The optional argument *count* is the maximum number of pattern occurrences 
to be
    replaced; *count* must be a non-negative integer.  If omitted or zero, all
-   occurrences will be replaced. Empty matches for the pattern are replaced 
only
-   when not adjacent to a previous empty match, so ``sub('x*', '-', 'abxd')`` 
returns
-   ``'-a-b--d-'``.
+   occurrences will be replaced.
+
+   Adjacent empty matches are not possible, but an empty match can occur
+   immediately after a non-empty match.
+   As a result, ``sub('x*', '-', 'abxd')`` returns ``'-a-b--d-'``
+   instead of ``'-a-b-d-'``.
 
    .. index:: single: \g; in regular expressions
 
@@ -1128,8 +1131,7 @@ Functions
    .. versionchanged:: 3.7
       Unknown escapes in *repl* consisting of ``'\'`` and an ASCII letter
       now are errors.
-      Empty matches for the pattern are replaced when adjacent to a previous
-      non-empty match.
+      An empty match can occur immediately after a non-empty match.
 
    .. versionchanged:: 3.12
       Group *id* can only contain ASCII digits.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to