久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python中re.findall函數(shù)實(shí)例用法

瀏覽:3日期:2022-08-07 08:29:41

1、findall函數(shù)返回字符串中所有匹配結(jié)果的正則表達(dá)式列表。

2、如果沒(méi)有分組的正則是返回的正則匹配,分組返回的是分組匹配而非整個(gè)正則匹配。

實(shí)例

找到所有與pattern匹配的子串(不重疊),并將其放入列表。

import relst = re.findall('[1-9]d*','qw21313h1o58p4kjh8123jkh8435u')for x in lst: print(x,end=' ')

#輸出結(jié)果:21313 1 58 4 8123 8435

實(shí)例擴(kuò)展:

python3中函數(shù)說(shuō)明:

findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more capturing groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.

兩種形式的使用方法:

import rekk = re.compile(r’d+’)kk.findall(’one1two2three3four4’)#[1,2,3,4] #注意此處findall()的用法,可傳兩個(gè)參數(shù);kk = re.compile(r’d+’)re.findall(kk,'one123')#[1,2,3]

其中,含()時(shí)要注意:

import restring='abcdefg acbdgef abcdgfe cadbgfe'#帶括號(hào)與不帶括號(hào)的區(qū)別#不帶括號(hào)regex=re.compile('((w+)s+w+)')print(regex.findall(string))#輸出:[(’abcdefg acbdgef’, ’abcdefg’), (’abcdgfe cadbgfe’, ’abcdgfe’)]regex1=re.compile('(w+)s+w+')print(regex1.findall(string))#輸出:[’abcdefg’, ’abcdgfe’]regex2=re.compile('w+s+w+')print(regex2.findall(string))#輸出:[’abcdefg acbdgef’, ’abcdgfe cadbgfe’]

到此這篇關(guān)于python中re.findall函數(shù)實(shí)例用法的文章就介紹到這了,更多相關(guān)python中re.findall函數(shù)的介紹內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 英山县| 宁南县| 吉木萨尔县| 乌兰察布市| 年辖:市辖区| 周宁县| 宜宾市| 江北区| 东乡县| 淄博市| 秦皇岛市| 白山市| 凤山市| 简阳市| 崇明县| 花莲县| 盘山县| 伊吾县| 高淳县| 黄山市| 宾川县| 怀安县| 夏津县| 措美县| 本溪| 福鼎市| 菏泽市| 揭西县| 西宁市| 梅河口市| 葫芦岛市| 四川省| 大埔县| 蒙阴县| 全椒县| 措勤县| 齐河县| 台中县| 乐业县| 黎城县| 洛扎县|