也许,
^(\d+(?:\.\d+)*)\s+([\s\S]*?)(?=^\d+(?:\.\d+)*)|^(\d+(?:\.\d+)*)\s+([\s\S]*)
可能有点接近获得我猜测的那些所需文本。
这里我们只需要查找开头的行,
^(\d+(?:\.\d+)*)\s+
然后,我们只需使用之后收集任何东西
([\s\S]*?)
直到下一行,
(?=^\d+(?:\.\d+)*)
然后,我们可能会也可能不会,取决于我们输入的样子,只剩下一个最后一个元素,我们将使用这个最后一个来收集它:
^(\d+(?:\.\d+)*)\s+([\s\S]*)
然后我们将(使用|)更改为先前的表达式。
尽管这种方法的代码很简单,但由于我们使用的是环视,所以它的性能相当慢,所以the other answer here 要好得多,如果时间复杂度是一个问题,这很可能是。
测试
import re
regex = r"^(\d+(?:\.\d+)*)\s+([\s\S]*?)(?=^\d+(?:\.\d+)*)|^(\d+(?:\.\d+)*)\s+([\s\S]*)"
string = """
I.S. EN 60601-1:2006&A1:2013&AC:2014&A12:2014
60601-1 © IEC:2005
60601-1 © IEC:2005
– 337 –
– 169 –
12.4.5.4 Other ME EQUIPMENT producing diagnostic or therapeutic radiation
When applicable, the MANUFACTURER shall address in the RISK MANAGEMENT PROCESS the
RISKS associated with ME EQUIPMENT producing diagnostic or therapeutic radiation other than
for diagnostic X-rays and radiotherapy (see 12.4.5.2 and 12.4.5.3).
Compliance is checked by inspection of the RISK MANAGEMENT FILE.
12.4.6 Diagnostic or therapeutic acoustic pressure
When applicable, the MANUFACTURER shall address in the RISK MANAGEMENT PROCESS the
RISKS associated with diagnostic or therapeutic acoustic pressure.
Compliance is checked by inspection of the RISK MANAGEMENT FILE.
13 * HAZARDOUS SITUATIONS and fault conditions
13.1 Specific HAZARDOUS SITUATIONS
* General
13.1.1
When applying the SINGLE FAULT CONDITIONS as described in 4.7 and listed in 13.2, one at a
time, none of the HAZARDOUS SITUATIONS in 13.1.2 to 13.1.4 (inclusive) shall occur in the
ME EQUIPMENT.
The failure of any one component at a time, which could result in a HAZARDOUS SITUATION, is
described in 4.7.
* Emissions, deformation of ENCLOSURE or exceeding maximum temperature
13.1.2
The following HAZARDOUS SITUATIONS shall not occur:
– emission of flames, molten metal, poisonous or ignitable substance in hazardous
quantities;
– deformation of ENCLOSURES to such an extent that compliance with 15.3.1 is impaired;
–
temperatures of APPLIED PARTS exceeding the allowed values identified in Table 24 when
measured as described in 11.1.3;
temperatures of ME EQUIPMENT parts that are not APPLIED PARTS but are likely to be
touched, exceeding the allowable values in Table 23 when measured and adjusted as
described in 11.1.3;
–
– exceeding the allowable values for “other components and materials” identified in Table 22
times 1,5 minus 12,5 °C. Limits for windings are found in Table 26, Table 27 and Table 31.
In all other cases, the allowable values of Table 22 apply.
Temperatures shall be measured using the method described in 11.1.3.
The SINGLE FAULT CONDITIONS in 4.7, 8.1 b), 8.7.2 and 13.2.2, with regard to the emission of
flames, molten metal or ignitable substances, shall not be applied to parts and components
where:
– The construction or the supply circuit limits the power dissipation in SINGLE FAULT
CONDITION to less than 15 W or the energy dissipation to less than 900 J.
"""
print(re.findall(regex, string, re.M))
输出
[('12.4.5.4', '其他生产诊断或治疗的 ME 设备
辐射 \n适用时,制造商应在
风险管理流程 与我相关的\n风险
产生诊断或治疗辐射的设备,但不包括
\n用于诊断 X 射线和放射治疗(参见 12.4.5.2 和 12.4.5.3)。
\n\n通过检查风险管理来检查合规性
FILE.\n\n', '', ''), ('12.4.6', '诊断或治疗声学
压力 \n适用时,制造商应在
风险管理过程与诊断相关的\n风险
或治疗声压。 \n\n合规性检查由
检查风险管理文件。\n\n', '', ''), ('13', '*
危险情况和故障情况\n\n', '', ''), ('13.1',
'特定危险情况\n\n* 一般\n\n', '', ''),
('13.1.1', '当应用单一故障条件时
在 4.7 中描述并在 13.2 中列出,一次一个\n,无
13.1.2 至 13.1.4(含)中的危险情况
应发生在\nME设备中。\n\n任何一个故障
一次的组件,这可能导致危险情况,是
\n在 4.7 中描述。 \n\n* 排放、外壳变形或
超过最高温度 \n\n', '', ''), ('', '', '13.1.2', 'The
不会发生以下危险情况:\n– 排放
火焰、熔融金属、有毒或易燃物质
危险\n\n数量; \n\n– ENCLOSURES 变形为这样的
符合 15.3.1 的程度受损; \n– \n\n温度
应用部分的数量超过中确定的允许值
表 24 当\n按 11.1.3 中所述测量时; \n温度
ME 设备部件不是应用部件,但可能
被\n触摸,超过表23中的允许值
当按照 11.1.3 中的描述进行测量和调整时; \n\n– \n\n–
超过“其他组件和材料”的允许值
在表 22 中确定\n乘以 1.5 - 12.5 °C。绕组限制
见表 26、表 27 和表 31。\n在所有其他情况下,
表 22 的允许值适用。 \n\n温度应为
使用 11.1.3 中描述的方法测量。 \n\n单一故障
4.7、8.1 b)、8.7.2 和 13.2.2 中的条件,关于
\n火焰、熔融金属或可燃物质的排放,
不得应用于零件和组件\n其中:\n–
建设或供电电路限制了功率
在单一故障\n\n条件下耗散到小于 15 W 或
能量耗散至小于 900 J。\n\n')]