也许,
^(\d+(?:\.\d+)*)\s+([\s\S]*?)(?=^\d+(?:\.\d+)*)|^(\d+(?:\.\d+)*)\s+([\s\S]*)
可能会有些接近我猜测的所需文本。
在这里,我们只需要寻找以以下内容开头的行:
^(\d+(?:\.\d+)*)\s+
然后,我们只需要使用以下方法收集后续内容:
([\s\S]*?)
直到下一行以以下内容开头,
(?=^\d+(?:\.\d+)*)
然后,根据输入的情况,我们可能只剩下最后一个元素,我们可以使用 "last" 来收集它。
^(\d+(?:\.\d+)*)\s+([\s\S]*)
我们将使用|
修改先前的表达式。
尽管这种方法编码简单,但在性能方面相当慢,因为我们使用了回顾,所以如果时间复杂度是一个问题,这里的其他答案会更好,这很可能会发生。
测试
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', '对于除诊断X光和放射治疗之外的其他产生诊断或治疗辐射的医疗设备,制造商应在风险管理过程中解决与此相关的风险。\n合规性通过检查风险管理文件来验证。', '', ''), ('12.4.6', '对于诊断或治疗声压,制造商应在风险管理过程中解决与此相关的风险。\n合规性通过检查风险管理文件来验证。', '', ''), ('13', '* 危险情况和故障条件\n\n', '', ''), ('13.1', '特定的危险情况\n\n* 一般 \n\n', '', ''), ('13.1.1', '当应用4.7中描述并列在13.2中的单一故障条件时,不应出现13.1.2至13.1.4(含)中的任何危险情况。\n其中任何一个组件单独故障可能导致危险情况,在4.7中有所描述。\n* 排放、外壳变形或超过最高温度\n\n', '', ''), ('', '', '13.1.2', '不应发生以下危险情况:\n- 在危险数量中排放火焰、熔融金属、有毒或易燃物质;\n- 外壳变形,以至于无法符合15.3.1的要求;\n- 应用部件的温度超过表24中所示的允许值,在11.1.3中描述的测量时;\n- 可能被触摸的医疗设备部件的温度超过表23中允许的值,在11.1.3中描述的测量和调整时;\n- 其他组件和材料的允许值超过表22中的1.5倍减去12.5°C。绕组的极限值在表26、表27和表31中找到。在所有其他情况下,适用表22的允许值。\n温度应使用11.1.3中描述的方法进行测量。\n在构造或供应电路限制单一故障条件的功率耗散小于15 W或能量耗散小于900 J的部件和组件中,不应应用4.7、8.1 b)、8.7.2和13.2.2中描述的关于火焰、熔融金属或易燃物质的单一故障条件。
^\d+(?:\.\d+)* +.*(?:\r?\n(?!\d+(?:\.\d+)* ).*)*
。https://regex101.com/r/eHXZ8x/1/ - The fourth bird