import re
s = "Background (UNASSIGNED): Previous study of ours showed that @PROG$ (ALI) and C-reactive protein (CRP) are independent significant prognostic factors in operable non-small cell lung cancer (NSCLC) patients."
print( re.sub(r'(@PROG\$\s+)\([A-Z]+\)', r'\1@PROG$', s) )
# => Background (UNASSIGNED): Previous study of ours showed that @PROG$ @PROG$ and C-reactive protein (CRP) are independent significant prognostic factors in operable non-small cell lung cancer (NSCLC) patients.
您可以使用
re.sub
解决方案,如见Python demo。正则表达式是
见regex demo。详情:
(@PROG\$\s+)
-group1(\1
指替换模式中的该组值):@PROG$
和一个或多个空格\(
-a(
字符[A-Z]+
-一个或多个大写ASCII字母(替换为[^()]*
,以匹配括号中除(
和)
之外的任何内容)\)
-a)
字符李>相关问题 更多 >
编程相关推荐