Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-99308: Clarify re docs for byte pattern group names #99311

Merged
merged 3 commits into from
Dec 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ The special characters are:
``(?P<name>...)``
Similar to regular parentheses, but the substring matched by the group is
accessible via the symbolic group name *name*. Group names must be valid
Python identifiers, and in bytes patterns they must contain only characters
in the ASCII range. Each group name must be defined only once within a
regular expression. A symbolic group is also a numbered group, just as if
Python identifiers, and in :class:`bytes` patterns they can only contain
bytes in the ASCII range. Each group name must be defined only once within
a regular expression. A symbolic group is also a numbered group, just as if
the group were not named.

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

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

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

Expand Down Expand Up @@ -496,6 +496,8 @@ The special characters are:

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


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

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


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