python利用正則表達式取值


#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







免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM