【发布时间】:2018-10-08 10:25:53
【问题描述】:
我正在尝试使用正则表达式解析文档中的文本。文档包含不同的结构,即第 1.2 节,第 (1) 节。下面的正则表达式能够解析带小数点的文本,但 () 失败。
处理以 () 开头的内容的任何建议。
例如:
import re
RAW_Data = '(4) The Governor-General may arrange\n with the Chief Minister of the Australian Capital Territory for the variation or revocation of an \n\narrangement in force under subsection (3). \nNorthern Territory \n (5) The Governor-General may make arrangements with the \nAdministrator of the Northern \nTerritory with respect to the'
f = re.findall(r'(^\d+\.[\d\.]*)(.*?)(?=^\d+\.[\d\.]*)', RAW_Data,re.DOTALL|re.M|re.S)
for z in f:
z=(''.join(z).strip().replace('\n',''))
print(z)
预期输出:
(4) 总督可与澳大利亚首都直辖区首席部长安排更改或撤销根据第
小节生效的安排(3) 北领地
(5) 总督可就“北领地行政长官”作出安排
【问题讨论】:
-
你能包含预期的输出吗?
标签: python regex python-3.x regex-greedy