Skip to content

Commit

Permalink
[3.7] bpo-38294: Add list of no-longer-escaped chars to re.escape doc…
Browse files Browse the repository at this point in the history
…umentation. (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)
  • Loading branch information
rbanffy authored and ned-deily committed Oct 14, 2019
1 parent 89f35fa commit ae41f62
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ form.
This is useful if you want to match an arbitrary literal string that may
have regular expression metacharacters in it. For example::

>>> print(re.escape('python.exe'))
python\.exe
>>> print(re.escape('http://www.python.org'))
http://www\.python\.org

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

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


.. function:: purge()
Expand Down
1 change: 1 addition & 0 deletions Doc/tools/susp-ignored.csv
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ whatsnew/3.7,,::,error::BytesWarning
whatsnew/changelog,,::,error::BytesWarning
whatsnew/changelog,,::,default::BytesWarning
whatsnew/changelog,,::,default::DeprecationWarning
library/re,,`,"`"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add list of no-longer-escaped chars to re.escape documentation

0 comments on commit ae41f62

Please sign in to comment.