贪婪模式和懒惰模式:贪婪模式是尽可能多的匹配,懒惰模式是尽可能少的匹配 string = "Poythony" pat1 = "p.*y" # 贪婪模式,比较模糊 pat2 = "p.*?y" # 懒惰模式,比较精准 # rst = re.search(pat, string) rst1 = re.search(pat1, string, re.I) # re.I:忽略大小写 rst2 = re.search(pat2, string, re.I) # re.I:忽略大小写 print(rst1) print(rst2) 打印结果: