summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-13 18:06:43 (GMT)
committerGitHub <noreply@github.com>2017-04-13 18:06:43 (GMT)
commit5908300e4b0891fc5ab8bd24fba8fac72012eaa7 (patch)
tree78b1b58197c890909b9d153a7988105498d56659 /Doc
parenta6e395dffadf8c5124903c01ad69fefa36b1a935 (diff)
downloadcpython-5908300e4b0891fc5ab8bd24fba8fac72012eaa7.zip
cpython-5908300e4b0891fc5ab8bd24fba8fac72012eaa7.tar.gz
cpython-5908300e4b0891fc5ab8bd24fba8fac72012eaa7.tar.bz2
bpo-29995: re.escape() now escapes only special characters. (#1007)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/re.rst10
-rw-r--r--Doc/tools/susp-ignored.csv2
2 files changed, 8 insertions, 4 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()
diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv
index df67f75..01b1d98 100644
--- a/Doc/tools/susp-ignored.csv
+++ b/Doc/tools/susp-ignored.csv
@@ -303,7 +303,7 @@ whatsnew/3.2,,:gz,">>> with tarfile.open(name='myarchive.tar.gz', mode='w:gz') a
whatsnew/3.2,,:location,zope9-location = ${zope9:location}
whatsnew/3.2,,:prefix,zope-conf = ${custom:prefix}/etc/zope.conf
library/re,,`,!#$%&'*+-.^_`|~:
-library/re,,`,\!\#\$\%\&\'\*\+\-\.\^_\`\|\~\:
+library/re,,`,!\#\$%&'\*\+\-\.\^_`\|~:
library/tarfile,,:xz,'x:xz'
library/xml.etree.elementtree,,:sometag,prefix:sometag
library/xml.etree.elementtree,,:fictional,"<actors xmlns:fictional=""http://characters.example.com"""