作者回复:
findall、match、sub、match分别是不同的函数功能,并非是扩展,例如search函数是找到第一个匹配的字符串,findall是找到所有匹配的字符串
根据需要使用不同的函数。如下:
import re
string = "x abc y 123 z 123"
pattern = re.compile(r'\d+')
print(re.search(pattern,string))
print(pattern.findall(string))
# 输出结果
# <re.Match object; span=(8, 11), match='123'>
# ['123', '123']
这些函数之间都可以配合使用的。