summaryrefslogtreecommitdiffstats
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 3213daf..ce90ec7 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -786,7 +786,7 @@ form.
.. function:: escape(pattern)
- Escape all the characters in *pattern* except ASCII letters, numbers and ``'_'``.
+ Escape special characters in *pattern*.
This is useful if you want to match an arbitrary literal string that may
have regular expression metacharacters in it. For example::
@@ -795,15 +795,19 @@ form.
>>> legal_chars = string.ascii_lowercase + string.digits + "!#$%&'*+-.^_`|~:"
>>> print('[%s]+' % re.escape(legal_chars))
- [abcdefghijklmnopqrstuvwxyz0123456789\!\#\$\%\&\'\*\+\-\.\^_\`\|\~\:]+
+ [abcdefghijklmnopqrstuvwxyz0123456789!\#\$%&'\*\+\-\.\^_`\|~:]+
>>> operators = ['+', '-', '*', '/', '**']
>>> print('|'.join(map(re.escape, sorted(operators, reverse=True))))
- \/|\-|\+|\*\*|\*
+ /|\-|\+|\*\*|\*
.. versionchanged:: 3.3
The ``'_'`` character is no longer escaped.
+ .. versionchanged:: 3.7
+ Only characters that can have special meaning in a regular expression
+ are escaped.
+
.. function:: purge()