mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
[3.13] gh-106482: Clarify documentation of character set in RE (GH-106517) (#132365)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Martin Panter <vadmium@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
6c8d527937
commit
c1744902c7
1 changed files with 12 additions and 3 deletions
|
@ -250,14 +250,23 @@ The special characters are:
|
|||
``[a\-z]``) or if it's placed as the first or last character
|
||||
(e.g. ``[-a]`` or ``[a-]``), it will match a literal ``'-'``.
|
||||
|
||||
* Special characters lose their special meaning inside sets. For example,
|
||||
* Special characters except backslash lose their special meaning inside sets.
|
||||
For example,
|
||||
``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
|
||||
``'*'``, or ``')'``.
|
||||
|
||||
.. index:: single: \ (backslash); in regular expressions
|
||||
|
||||
* Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
|
||||
inside a set, although the characters they match depend on the flags_ used.
|
||||
* Backslash either escapes characters which have special meaning in a set
|
||||
such as ``'-'``, ``']'``, ``'^'`` and ``'\\'`` itself or signals
|
||||
a special sequence which represents a single character such as
|
||||
``\xa0`` or ``\n`` or a character class such as ``\w`` or ``\S``
|
||||
(defined below).
|
||||
Note that ``\b`` represents a single "backspace" character,
|
||||
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.
|
||||
|
||||
.. index:: single: ^ (caret); in regular expressions
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue