库
import re
函数
print(re.search(r'do(es)?|did','does you'))
匹配成功返回第一个成功的匹配;匹配失败返回None。
print(re.findall(r"r[ua]n", "I run on the road where you ran before."))
返回所有匹配成功的字符串列表。若没匹配成功返回空列表。
print(re.sub(r"bad","nice","hello bad girl"))
返回替换匹配位置的字符串,比str.replace()更加灵活。
print(re.split(r"[,.; ]","h,a.p;p y"))
返回一个分割后的字符串列表,灵活过str.split()。