代码点读机 / Python / re.compile

re.compile Python · 模块功能

把正则表达式编译成可重复使用的对象。

怎么用

import re
re.compile(pattern)

小例子

import re
p = re.compile(r'\d+')
print(p.findall('a1b23'))

运行结果

['1', '23']

提醒:多次复用更高效。

官方文档:https://docs.python.org/zh-cn/3/library/re.html#re.compile

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条