gpt4 book ai didi

Python搜索两个词正则表达式

转载 作者:太空宇宙 更新时间:2023-11-04 08:07:52 25 4
gpt4 key购买 nike

我试图找出一个句子是否包含短语“go * to”,例如“go over to”、“go up to”等。我正在使用 Textblob,我知道我可以只使用下面:

search_go_to = set(["go", "to"])
go_to_blob = TextBlob(var)
matches = [str(s) for s in go_to_blob.sentences if search_go_to & set(s.words)]
print(matches)

但这也会返回诸如“去那儿把这个带给他”之类的句子,这是我不想要的。任何人都知道我如何做类似 text.find("go * to") 的事情?

最佳答案

尝试使用:

for match in re.finditer(r"go\s+\w+\s+to", text, re.IGNORECASE):

关于Python搜索两个词正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28004731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com