aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst28
1 files changed, 18 insertions, 10 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index a91bac53fb4..75ebbf11c8e 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -266,7 +266,7 @@ The special characters are:
not a word boundary as outside a set, and numeric escapes
such as ``\1`` are always octal escapes, not group references.
Special sequences which do not match a single character such as ``\A``
- and ``\Z`` are not allowed.
+ and ``\z`` are not allowed.
.. index:: single: ^ (caret); in regular expressions
@@ -661,11 +661,17 @@ character ``'$'``.
matches characters which are neither alphanumeric in the current locale
nor the underscore.
-.. index:: single: \Z; in regular expressions
+.. index:: single: \z; in regular expressions
+ single: \Z; in regular expressions
-``\Z``
+``\z``
Matches only at the end of the string.
+ .. versionadded:: 3.14
+
+``\Z``
+ The same as ``\z``. For compatibility with old Python versions.
+
.. index::
single: \a; in regular expressions
single: \b; in regular expressions
@@ -985,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
@@ -1089,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
@@ -1122,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.