例如提取:<title>xxxxxx</title>
想指定xxx(.*)前肯定会出现<title>,就用正后发断言,表达式:(?<=<title>).*
向指定xxx后边肯定会出现</title>,就用正先行断言,表达式:.*(?=</title>)
两个加在一起,就是(?<=<title>).*(?=</title>)
import re
#根据数据结果设置正则匹配方式
get_hehe = """(?<=hehe).*(?=hehe)"""
get_hehe_pattern = re.compile(get_hehe)
input_string = "你们这是hehe自寻死路hehe"
print(re.search(get_hehe_pattern, input_string)[0])
#输出:自寻死路