下面的代码是关于python通过正则获取字符串指定开头和结尾的中间字符串的代码,应该能对各位朋友有些好处。

def GetMiddleStr(content,startStr,endStr): patternStr = r'%s(.+?)%s'%(startStr,endStr) p = re.compile(patternStr,re.IGNORECASE) m= re.match(p,content) if m: return m.group(1)