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

Skip to content

Commit 15ae75d

Browse files
rbanffyserhiy-storchaka
authored andcommitted
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.
1 parent 60ec6ef commit 15ae75d

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
@@ -356,3 +356,4 @@ whatsnew/changelog,,::,default::BytesWarning
356356
whatsnew/changelog,,::,default::DeprecationWarning
357357
library/importlib.metadata,,:main,"EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts')"
358358
library/importlib.metadata,,`,loading the metadata for packages for the indicated ``context``.
359+
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-e 31C7 scaped chars to re.escape documentation

0 commit comments

Comments
 (0)
0