【发布时间】:2018-11-16 06:21:51
【问题描述】:
我有一些格式的内容:
text = """Pos no
...
... 25/gm
The Text to be
...
excluded
Pos no
...
... 46 kg
The Text to be
...
excluded
Pos no
...
... 46 xunit
End of My Text
在哪里,
Pos no... 25/gm - 这是一种表格结构,我必须从中提取值。
The Text to be ... excluded - 这有恒定的开始(比如说The Text to be),但没有明确的结束,即excluded 可能不存在。
End of My Text -
此文本将始终存在。
我想要一个仅包含表格内容的列表,即
["Pos no
...
... 25/gm",
"Pos no
...
... 46 kg",
"Pos no
...
... 46 xunit"]
这是我的尝试,但它没有获取正确的列表:
re.findall(r'(Pos no .+?)(?: |The Text to be|End of My Text)', text, re.DOTALL | re.M)
【问题讨论】:
标签: python regex multiline multilinestring