python--正则匹配首尾标签中间的内容

import re

it = re.finditer(r".*?", '被筛选字符串')   # 匹配url标签里的内容
# it = re.finditer(r".*?", con)   # 匹配标签里的内容,有换行符\n导致匹配失败
it2 = re.finditer(r"[\s\S]*?", '被筛选字符串')   # 成功匹配方法1
# it = re.finditer(r"[\d\D]*?", con)  # 成功匹配方法2

for match in it:
   ret = match.group()
   print(ret)
for match in it2:
   ret = match.group()
   print(ret)

你可能感兴趣的:(python--正则匹配首尾标签中间的内容)