import re
‘’‘
输出select和from之间的单词
’‘’
str = 'select\n pid,\n price\nfrom \n table1\nwhere \n dt between \'20200101\' and \'20200913\'\ngroup by \n pid'
str = str.replace("\n", " ") # 去掉换行符
#print(str)
word1 = 'select'
word2 = 'from'
pattern = re.compile(word1+'(.*?)'+word2,re.S)
result = pattern.findall(str)
print(result)
re.compile():正则表达式,返回的是一个匹配对象。