免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
正則表達(dá)式 re.findall 用法

正則 re.findall 的簡單用法(返回string中所有與pattern相匹配的全部字串,返回形式為數(shù)組)
語法:

findall(pattern, string, flags=0)

import re

Python 正則表達(dá)式 re findall 方法能夠以列表的形式返回能匹配的子串

print (help(re.findall))
print (dir(re.findall))

findall查找全部r標(biāo)識(shí)代表后面是正則的語句

regular_v1 = re.findall(r"docs","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v1)
# ['docs']

符號^表示匹配以https開頭的的字符串返回,

regular_v2 = re.findall(r"^https","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v2)
# ['https']

用$符號表示以html結(jié)尾的字符串返回,判斷是否字符串結(jié)束的字符串

regular_v3 = re.findall(r"html$","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v3)
# ['html']

[...]匹配括號中的其中一個(gè)字符

regular_v4 = re.findall(r"[t,w]h","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v4)
# ['th', 'wh']

“d”是正則語法規(guī)則用來匹配0到9之間的數(shù)返回列表

regular_v5 = re.findall(r"\d","https://docs.python.org/3/whatsnew/3.6.html")
regular_v6 = re.findall(r"\d\d\d","https://docs.python.org/3/whatsnew/3.6.html/1234")
print (regular_v5)
# ['3', '3', '6']
print (regular_v6)
# ['123']

小d表示取數(shù)字0-9,大D表示不要數(shù)字,也就是出了數(shù)字以外的內(nèi)容返回

regular_v7 = re.findall(r"\D","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v7)
# ['h', 't', 't', 'p', 's', ':', '/', '/', 'd', 'o', 'c', 's', '.', 'p', 'y', 't', 'h', 'o', 'n', '.', 'o', 'r', 'g', '/', '/', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '/', '.', '.', 'h', 't', 'm', 'l']

“w”在正則里面代表匹配從小寫a到z,大寫A到Z,數(shù)字0到9

regular_v8 = re.findall(r"\w","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v8)
#['h', 't', 't', 'p', 's', 'd', 'o', 'c', 's', 'p', 'y', 't', 'h', 'o', 'n', 'o', 'r', 'g', '3', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '3', '6', 'h', 't', 'm', 'l']

“W”在正則里面代表匹配除了字母與數(shù)字以外的特殊符號

regular_v9 = re.findall(r"\W","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v9)
# [':', '/', '/', '.', '.', '/', '/', '/', '.', '.']
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
爬蟲常用正則、re.findall 使用
python 正則表達(dá)式re findall
Python學(xué)習(xí)常用網(wǎng)站(贈(zèng)Python書籍)
用Python寫簡單爬蟲
爬蟲 | Python 自動(dòng)下載百度圖片
通過python爬取kanunu8某小說所有章節(jié)的內(nèi)容,并按章節(jié).txt保存
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服