python正则表达式,根据左右关键字,匹配中间内容
import re stringA = "abcdefghijk" pattern = re.compile(r'd(.+?)h') # 匹配d和h中间的内容 print(re.findall(pattern, stringA)) # ['efg'] stringB = "abcdefg(python)hijk" pattern = re.compile(r'[(](.*)[)]') # 匹配括号内的内容 print(re.findall(pattern, stringB)) # ['python']
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/16599560.html