【发布时间】:2021-08-01 08:34:50
【问题描述】:
我想在特定单词之后提取单词。例如,对于txt = 'I like to eat apple. Me too.',我想提取apple 之后的所有单词,即'.我也是。'
我试过了
re.findall(r"(apple[^.]*\.)",txt)
但它返回到'apple.'
我也试过
`re.findall(r"([^.]*?apple[^.]*\.)",txt)`
返回'I like to eat apple.'
【问题讨论】:
-
这能回答你的问题吗? Finding words after keyword in python
-
也许我遗漏了一些东西,但正则表达式不应该像
apple(.*)$一样简单吗?apple匹配关键字,然后(.*)$捕获其他所有内容,直到 eol?