python如何实现文本匹配

想用python以下需求的文本匹配:

我有个excel表,取同一行中的token1和token2的值组成类似一个词组,并在txt文档中匹配出既包含token1,又包含token2的文本。

img

比如图中的第三行中token1和token2的值为"悲伤"和“安慰”,那在txt文档中如何匹配出同时包含这两个词的文本出来。其中我将txt文档按分隔符[!, ?,。]划分为每个句子。

想要达到的效果是匹配出的每一句话同时包含同一行中token1和token2的值。比如:
第3行中的[悲伤,安慰]这两个词匹配出句子:她看到朋友悲伤,就去安慰了他。

我尝试将这两列写成pattern,如果可行,下一步该怎么匹配txt文档呢?

stop_words = ['?', '?', '!', '!', '。', ';', ';', ',', ',']

line_num = 0
with open(txt_path, 'r', encoding='utf-8', errors='ignore') as f:
    for line in f:
        line_num += 1

def merge(head, tail):
    pattern = '.* {}?( .* | ){} .*'.format(head, tail)
    return pattern

df = pd.read_excel(excel_path)
df['pattern'] = df.apply(lambda row: merge(row['token1'], row['token2']), axis=1)

不知道用什么方法好,请大家帮忙!感谢!

都写出正则了,不就直接读取txt匹配就行了