我有一个包含大量数据列表的文件,类似于这样:
#fabulous 7.526 2301 2
#excellent 7.247 2612 3
#superb 7.199 1660 2
#perfection 7.099 3004 4
#terrific 6.922 629 1
我有一个文件,里面包含了一系列这样的句子:
Terrific Theo Walcott is still shit, watch Rafa and Johnny deal with him on Saturday.
its not that I'm a GSP fan, fabulous
Iranian general says Israel's Iron Dome can't deal with their missiles
with J Davlar 11th. Main rivals are team Poland.
我想用正则表达式检查以下内容:
每个句子的第一个单词是否与文件中的任何单词匹配。例如,如果Terrific、its、Iranian出现在文件中或不出现。
每个句子的最后一个单词是否与文件中的任何单词匹配。例如,如果saturday、fabulous、missiles、Poland出现在文件中或不出现。
句子中各个单词的前缀和后缀(2或3个字符)是否与文件中的前缀和后缀(2或3个字符)匹配。例如,如果Ter、its、Ira、wi与文件中任何单词的2或3个前缀匹配或不匹配。后缀同理。
我对正则表达式非常陌生,但我能想到这种方式,但没有得到结果:term2.lower()是文件中的第一列。
wordanalysis["trail"] = found if re.match(sentence[-1],term2.lower()) else not(found)
wordanalysis["lead"] = found if re.match(sentence[0],term2.lower()) else not(found)