Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python的re模块为何转义分号字符_Python_Regex_Python 2.7 - Fatal编程技术网

Python的re模块为何转义分号字符

Python的re模块为何转义分号字符,python,regex,python-2.7,Python,Regex,Python 2.7,为什么Python的re模块转义分号字符 print(re.escape('text;text')) 提供以下输出: text\;text 它逃避分号,因为这是它的设计目的。根据,它将转义所有非字母数字字符 返回所有非字母数字反斜杠的字符串;如果要匹配可能包含正则表达式元字符的任意文字字符串,这将非常有用 它逃避;分号,因为;不是字母数字字符。因为它考虑;作为一个特殊字符。因为转义例程非常简单:它转义所有的非字母数字字符。你期望得到什么? >>> re.escape.__d

为什么Python的re模块转义分号字符

print(re.escape('text;text'))
提供以下输出:

text\;text

它逃避分号,因为这是它的设计目的。根据,它将转义所有非字母数字字符

返回所有非字母数字反斜杠的字符串;如果要匹配可能包含正则表达式元字符的任意文字字符串,这将非常有用


它逃避;分号,因为;不是字母数字字符。

因为它考虑;作为一个特殊字符。因为转义例程非常简单:它转义所有的非字母数字字符。你期望得到什么?
>>> re.escape.__doc__
'Escape all non-alphanumeric characters in pattern.'