mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
#2650: re.escape() no longer escapes the "_".
This commit is contained in:
parent
344d26c7a0
commit
88fdeb45ef
4 changed files with 15 additions and 8 deletions
|
@ -215,12 +215,14 @@ def template(pattern, flags=0):
|
|||
return _compile(pattern, flags|T)
|
||||
|
||||
_alphanum_str = frozenset(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
_alphanum_bytes = frozenset(
|
||||
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
b"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
|
||||
def escape(pattern):
|
||||
"Escape all non-alphanumeric characters in pattern."
|
||||
"""
|
||||
Escape all the characters in pattern except ASCII letters, numbers and '_'.
|
||||
"""
|
||||
if isinstance(pattern, str):
|
||||
alphanum = _alphanum_str
|
||||
s = list(pattern)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue