python re.escape()方法

re.escape()()方法

python re模块中的escape()方法,可以转义参数指定的正则表达式字符串中的特殊字符,接受ASCII字母,数字 和下划线'_'。


语法

escape(pattern)

python源码对escape()方法的介绍:

Escape all the characters in pattern except ASCII letters, numbers and '_'.

参数

参数描述
pattern必须参数,指定正则表达式,为python字符串类型

返回值

正则表达式对象。


re.escape()方法实例代码

>>> import re
>>> re.escape('abcde/_')
'abcde\\/_'
>>> re.escape('fgh^%"')
'fgh\\^\\%\\"'

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.