python--正则匹配首尾标签中间的内容
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)
python 中文名:蟒蛇,设计者:Guido van Rossum