【发布时间】:2018-11-23 10:59:05
【问题描述】:
这是一个关于编程的学校项目,我应该只使用重新导入。
我试图在包含由参数定义的特定表达式的文本文件中查找所有句子并将它们提取到列表中。搜索其他帖子让我找到了句子开头和结尾的点,但如果那里有一个带点的数字,它会破坏结果。
如果我有一个 txt:This is a text. I dont want for the result to stop in the number 990.576, I want to extract the phrase with this expression. Its not working.
search = re.findall(r"([^.]*?"+expression+"[^.]*\.", txt)
我得到的结果是['576, I want to extract the phrase with this expression',]
我想要的结果是['I dont want for the result to stop in the number 990.576, I want to extract the phrase with this expression.']
我还是初学者,有什么帮助吗?
【问题讨论】:
-
首先搜索数字之间的点,用逗号替换。然后拆分您的文本并在生成的短语中,再次查找带逗号的数字并将该逗号替换为一个点。