我正在尝试编写一个正则表达式,它将在句子列表中找到“松鼠”这个词。该表达式应返回包含单词“squirrel”的完整句子列表。
包含单词“squirrel”的句子可能类似于以下句子:
松鼠有一条长尾巴 (.) 说 (.) 长尾巴。
猫 (a)n(d) 松鼠 (a)n(d) 兔子 (a)n(d) 兔子 (a)n(d) (.)
松鼠+有尾巴
我现在re
的样子是这样的
word_only += re.findall('(.*?' + word + '?!\S)', sentence)
word_only += re.findall('.*?' + word + '\S+', sentence)
但它只返回单词(“squirrel”)前面的内容,而不是后面的内容。
有任何想法吗?谢谢