Skip to content

Commit 43f5c0c

Browse files
rbanffyserhiy-storchaka
authored andcommitted
[3.7] bpo-38294: Add list of no-longer-escaped chars to re.escape documentation. (GH-16442) (GH-16647)
Prior to 3.7, re.escape escaped many characters that don't have special meaning in Python, but that use to require escaping in other tools and languages. This commit aims to make it clear which characters were, but are no longer escaped. (cherry picked from commit 15ae75d)
1 parent 98043b4 commit 43f5c0c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Doc/library/re.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ form.
925925
This is useful if you want to match an arbitrary literal string that may
926926
have regular expression metacharacters in it. For example::
927927

928-
>>> print(re.escape('python.exe'))
929-
python\.exe
928+
>>> print(re.escape('http://www.python.org'))
929+
http://www\.python\.org
930930

931931
>>> legal_chars = string.ascii_lowercase + string.digits + "!#$%&'*+-.^_`|~:"
932932
>>> print('[%s]+' % re.escape(legal_chars))
@@ -949,7 +949,9 @@ form.
949949

950950
.. versionchanged:: 3.7
951951
Only characters that can have special meaning in a regular expression
952-
are escaped.
952+
are escaped. As a result, ``'!'``, ``'"'``, ``'%'``, ``"'"``, ``','``,
953+
``'/'``, ``':'``, ``';'``, ``'<'``, ``'='``, ``'>'``, ``'@'``, and
954+
``"`"`` are no longer escaped.
953955

954956

955957
.. function:: purge()

Doc/tools/susp-ignored.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,4 @@ whatsnew/3.7,,::,error::BytesWarning
354354
whatsnew/changelog,,::,error::BytesWarning
355355
whatsnew/changelog,,::,default::BytesWarning
356356
whatsnew/changelog,,::,default::DeprecationWarning
357+
library/re,,`,"`"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add list of no-longer-escaped chars to re.escape documentation

0 commit comments

Comments
 (0)