8000 bpo-38294: Add list of no-longer-escaped chars to re.escape documenta… · python/cpython@b731fc5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b731fc5

Browse files
bpo-38294: Add list of no-longer-escaped chars to re.escape documentation. (GH-16442)
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) Co-authored-by: Ricardo Bánffy <rbanffy@gmail.com>
1 parent 435b2ee commit b731fc5

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
@@ -931,8 +931,8 @@ form.
931931
This is useful if you want to match an arbitrary literal string that may
932932
have regular expression metacharacters in it. For example::
933933

934-
>>> print(re.escape('python.exe'))
935-
python\.exe
934+
>>> print(re.escape('http://www.python.org'))
935+
http://www\.python\.org
936936

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

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

960962

961963
.. 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/changelog,,::,default::BytesWarning
354354
whatsnew/changelog,,::,default::DeprecationWarning
355355
library/importlib.metadata,,:main,"EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts')"
356356
library/importlib.metadata,,`,loading the metadata for packages for the indicated ``context``.
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)
0