# re.Istring忽略大小写string1 = "HeLLO word"pattern2 = re.compile(r"hello",re.I)rett = pattern2.search(string1)print(rett.group())#输出结果:HeLLO # re.S视为单行模式string2 = """<div>别国风光,千里冰封,万里雪飘望长城内外,惟余莽莽,大河上下,顿失滔滔</div>"""pattern3 = re.compile(r"<div>.*</div>",re.S)rett1 = pattern3.search(string2)print(rett1.group())# 输出结果:"""<div>别国风光,千里冰封,万里雪飘望长城内外,惟余莽莽,大河上下,顿失滔滔</div>""" # re.M视为多行模式string3 = """刘德华love刘德华love爱德华"""pattern4 = re.compile(r"^love",re.M)rett2 = pattern4.search(string3)print(rett2.group())# 输出结果:love
原文地址:https://www.cnblogs.com/kuangkuangduangduang/p/10373659.html
时间: 2024-10-28 21:44:50