正则取值

#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
posted @ 2019-06-11 20:11  猫有九命  阅读(727)  评论(0编辑  收藏  举报