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

Appearance settings

Commit 1557da6

Browse filesBrowse files
serhiy-storchakavadmiumhugovk
authored
gh-106482: Clarify documentation of character set in RE (#106517)
Co-authored-by: Martin Panter <vadmium@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 5fbe23e commit 1557da6
Copy full SHA for 1557da6

File tree

Expand file treeCollapse file tree

1 file changed

+12
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-3
lines changed

‎Doc/library/re.rst

Copy file name to clipboardExpand all lines: Doc/library/re.rst
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,23 @@ The special characters are:
250250
``[a\-z]``) or if it's placed as the first or last character
251251
(e.g. ``[-a]`` or ``[a-]``), it will match a literal ``'-'``.
252252

253-
* Special characters lose their special meaning inside sets. For example,
253+
* Special characters except backslash lose their special meaning inside sets.
254+
For example,
254255
``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
255256
``'*'``, or ``')'``.
256257

257258
.. index:: single: \ (backslash); in regular expressions
258259

259-
* Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
260-
inside a set, although the characters they match depend on the flags_ used.
260+
* Backslash either escapes characters which have special meaning in a set
261+
such as ``'-'``, ``']'``, ``'^'`` and ``'\\'`` itself or signals
262+
a special sequence which represents a single character such as
263+
``\xa0`` or ``\n`` or a character class such as ``\w`` or ``\S``
264+
(defined below).
265+
Note that ``\b`` represents a single "backspace" character,
266+
not a word boundary as outside a set, and numeric escapes
267+
such as ``\1`` are always octal escapes, not group references.
268+
Special sequences which do not match a single character such as ``\A``
269+
and ``\Z`` are not allowed.
261270

262271
.. index:: single: ^ (caret); in regular expressions
263272

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.