python通过正则获取字符串指定开头和结尾的中间字符串的代码

下面的代码是关于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)

猜你喜欢

转载自blog.51cto.com/14142860/2348715