Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3cc400

Browse files
[3.14]gh-122055: Clarify documentation for empty matches in RE (GH-133169) (GH-134217)
(cherry picked from commit44b73d3)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parentd9c08c5 commite3cc400

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

‎Doc/library/re.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ Functions
991991
That way, separator components are always found at the same relative
992992
indices within the result list.
993993

994-
Emptymatchesfor the pattern split the string only when not adjacent
995-
to a previousempty match.
994+
Adjacent emptymatchesare not possible, but an empty match can occur
995+
immediately after a non-empty match.
996996

997997
..code::pycon
998998
@@ -1095,9 +1095,12 @@ Functions
10951095

10961096
The optional argument *count* is the maximum number of pattern occurrences to be
10971097
replaced; *count* must be a non-negative integer. If omitted or zero, all
1098-
occurrences will be replaced. Empty matches for the pattern are replaced only
1099-
when not adjacent to a previous empty match, so ``sub('x*', '-', 'abxd')`` returns
1100-
``'-a-b--d-'``.
1098+
occurrences will be replaced.
1099+
1100+
Adjacent empty matches are not possible, but an empty match can occur
1101+
immediately after a non-empty match.
1102+
As a result, ``sub('x*', '-', 'abxd')`` returns ``'-a-b--d-'``
1103+
instead of ``'-a-b-d-'``.
11011104

11021105
..index::single: \g; in regular expressions
11031106

@@ -1128,8 +1131,7 @@ Functions
11281131
..versionchanged::3.7
11291132
Unknown escapes in *repl* consisting of ``'\'`` and an ASCII letter
11301133
now are errors.
1131-
Empty matches for the pattern are replaced when adjacent to a previous
1132-
non-empty match.
1134+
An empty match can occur immediately after a non-empty match.
11331135

11341136
..versionchanged::3.12
11351137
Group *id* can only contain ASCII digits.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp