问题描述
In [3]: re.findall(r"([^.]*?apple[^.]*\.)",txt)
Out[4]: ['I like to eat apple.', " Let's go buy some apples."]
解决方法
我正在尝试从文本中提取所有包含指定单词的句子。
txt="I like to eat apple. Me too. Let's go buy some apples."
txt = "." + txt
re.findall(r"\."+".+"+"apple"+".+"+"\.",txt)
但它正在回报我:
[".I like to eat apple. Me too. Let's go buy some apples."]
代替 :
[".I like to eat apple.,"Let's go buy some apples."]
有什么帮助吗?