小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

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

 冥冥雎鳩 2023-10-10 發(fā)布于廣東

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

findall(pattern, string, flags=0)

import re

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

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

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

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

符號(hào)^表示匹配以https開頭的的字符串返回,

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

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

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

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

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

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

regular_v5 = re.findall(r"\d","https://docs./3/whatsnew/3.6.html")
regular_v6 = re.findall(r"\d\d\d","https://docs./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./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./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ù)字以外的特殊符號(hào)

regular_v9 = re.findall(r"\W","https://docs./3/whatsnew/3.6.html")
print (regular_v9)
# [':', '/', '/', '.', '.', '/', '/', '/', '.', '.']

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多