我的目标是识别出现在@PROG$之后的缩写词,并将其更改为@PROG$。(例如,阿里-> @PROG$)
输入
背景(未指定):我们先前的研究表明@PROG$ (ALI)和C-反应蛋白(CRP)是可手术性非小细胞肺癌(NSCLC)患者独立的重要预后因素。
输出
背景(未指定):我们先前的研究表明,@PROG$ @PROG$和C-反应性蛋白(CRP)是可手术性非小细胞肺癌(NSCLC)患者独立的重要预后因素。
我试过这样的re.findall('(\(.*?\))', s),它给了我所有的缩略语。这里有什么帮助吗?我需要修理什么?
发布于 2020-12-21 21:37:57
您可以使用re.sub解决方案,如
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.见Python演示。判断力
(@PROG\$\s+)\([A-Z]+\)见regex演示。详细信息:
(@PROG\$\s+) - Group 1 (\1指替换模式中的组值):@PROG$和一个或多个空白空间\( -a ( char[A-Z]+ -一个或多个大写ASCII字母(用[^()]*替换以匹配除(和)以外的括号中的任何内容)\) -a ) char.https://stackoverflow.com/questions/65400118
复制相似问题