正则取值

#coding=utf-8
import re
from urllib.parse import parse_qsl
'''
公式:
知道前后取中间,遇到字符加转义;
取到末尾的后面补一个$

'''
#利用正则表达式取值
#第一种:取中间的值,用(.+?),知道前后取中间,遇到字符加转义
a = 'value="abcbdbxbxbbb"'
r=re.findall('value="(.+?)"',a)
print (r[0])
打印的结果:abcbdbxbxbbb

#第二种,取到末尾的后面补一个$,取b=hello
a = "https://xxx.com/?a=helloworld&b=hello"
r=re.findall('ld&(.+?)$',a)
print (r[0])
打印的结果:b=hello

#我要取a=helloworld
a=re.findall('com/?(.+?)&',a)
print (a[0])
打印的结果:a=helloworld
人生苦短,我用python!
原文地址:https://www.cnblogs.com/YangQingHong/p/11005733.html