print re.sub("\((I+|i+|[a-z0-9])\)","\n\g<0>",buff)
会产生
The Integrated Programme Framework of the ISSSS has been established to:
(a) create a protective environment for civilians by strengthening the security forces, and improving discipline and control;
(b) support the demobilization and reintegration of armed groups;
(c) re-establish state functions in areas formerly controlled by armed groups, through the training and deployment of state officials (police, penitentiary, judicial and administration) to uphold the rule of law and public order,
(d) ensure open road access and infrastructure;
(e) promote a safe and dignified return of internally displaced persons and refugees; and
(f) address priority social needs and key sources of conflict and initiate economic recovery.
我对制作一个完全“通用”的产品持怀疑态度,因为您遇到了连字符的问题,例如“重新建立”。上面的正则表达式应该涵盖你的大部分情况,你应该能够通过在“|”中添加或删除内容来轻松地对其进行调整 操作员。话虽如此,我还是多玩了一点,加了一个测试句,效果还不错。我必须假设我从一个空格开始,以避免使用一些潜在的问题,如 ')'、'." 或 '-'。
>>> buff += "This is a) test of i) one ii) two iii) three a. four and b- five"
>>> print re.sub(" \({0,1}(I+|i+|[a-zA-Z0-9])(\)|\.|-)","\n\g<0>",buff)
The Integrated Programme Framework of the ISSSS has been established to:
(a) create a protective environment for civilians by strengthening the security forces, and improving discipline and control;
(b) support the demobilization and reintegration of armed groups;
(c) re-establish state functions in areas formerly controlled by armed groups, through the training and deployment of state officials (police, penitentiary, judicial and administration) to uphold the rule of law and public order,
(d) ensure open road access and infrastructure;
(e) promote a safe and dignified return of internally displaced persons and refugees; and
(f) address priority social needs and key sources of conflict and initiate economic recovery.This is
a) test of
i) one
ii) two
iii) three
a. four and
b- five