这应该在不使用正则表达式的情况下工作。text = 'MUMBAI_SATARA_TIC_IND_MT_CD.xml'if '_CD' in text: ext_CD = text[text.find('_CD'):text.find('_CD')+3]print(ext_CD)## text.find('_CD'), gives you the staring index of the substring '_CD'## text.find('_CD') + 3, gives you the ending index of the substring '_CD'## with that, ext_cd = text[24:27]Output:_CD