Skip to content

Commit dbc1e69

Browse files
authored
gh-99308: Clarify re docs for byte pattern group names (#99311)
1 parent b9aa14a commit dbc1e69

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Doc/library/re.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ The special characters are:
395395
``(?P<name>...)``
396396
Similar to regular parentheses, but the substring matched by the group is
397397
accessible via the symbolic group name *name*. Group names must be valid
398-
Python identifiers, and in bytes patterns they must contain only characters
399-
in the ASCII range. Each group name must be defined only once within a
400-
regular expression. A symbolic group is also a numbered group, just as if
398+
Python identifiers, and in :class:`bytes` patterns they can only contain
399+
bytes in the ASCII range. Each group name must be defined only once within
400+
a regular expression. A symbolic group is also a numbered group, just as if
401401
the group were not named.
402402

403403
Named groups can be referenced in three contexts. If the pattern is
@@ -419,8 +419,8 @@ The special characters are:
419419
+---------------------------------------+----------------------------------+
420420

421421
.. versionchanged:: 3.12
422-
In bytes patterns group names must contain only characters in
423-
the ASCII range.
422+
In :class:`bytes` patterns, group *name* can only contain bytes
423+
in the ASCII range (``b'\x00'``-``b'\x7f'``).
424424

425425
.. index:: single: (?P=; in regular expressions
426426

@@ -496,6 +496,8 @@ The special characters are:
496496

497497
.. versionchanged:: 3.12
498498
Group *id* can only contain ASCII digits.
499+
In :class:`bytes` patterns, group *name* can only contain bytes
500+
in the ASCII range (``b'\x00'``-``b'\x7f'``).
499501

500502

501503
The special sequences consist of ``'\'`` and a character from the list below.
@@ -1018,8 +1020,8 @@ Functions
10181020

10191021
.. versionchanged:: 3.12
10201022
Group *id* can only contain ASCII digits.
1021-
In bytes replacement strings group names must contain only characters
1022-
in the ASCII range.
1023+
In :class:`bytes` replacement strings, group *name* can only contain bytes
1024+
in the ASCII range (``b'\x00'``-``b'\x7f'``).
10231025

10241026

10251027
.. function:: subn(pattern, repl, string, count=0, flags=0)

0 commit comments

Comments
 (0)