导入re模块
import re
# 正则提取前部的值,"^(.+?)后",^表示从头开始匹配,返回列表
result = re.findall("^(.+?)345", '123wersdfsd345')
print(result)
print(result[0])
# 正则提取中间的值,"前(.+?)后",返回列表
result = re.findall("123(.+?)345", '123wersdfsd345')
print(result)
print(result[0])
# 正则提取尾部的值,"前(.+?)",返回列表
result = re.findall("123(.+?)$", '123wersdfsd345')
print(result)
print(result[0])