import re it = re.finditer(r"<url>.*?</url>", ‘被筛选字符串‘) # 匹配url标签里的内容 # it = re.finditer(r"<command>.*?</command>", con) # 匹配标签里的内容,有换行符\n导致匹配失败 it2 = re.finditer(r"<command>[\s\S]*?</command>", ‘被筛选字符串‘) # 成功匹配方法1 # it = re.finditer(r"<command>[\d\D]*?</command>", con) # 成功匹配方法2 for match in it: ret = match.group() print(ret) for match in it2: ret = match.group() print(ret)
原文地址:https://www.cnblogs.com/lutt/p/12207855.html
时间: 2024-11-13 02:36:37