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

您的位置:首頁技術文章
文章詳情頁

python中re.findall函數實例用法

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

1、findall函數返回字符串中所有匹配結果的正則表達式列表。

2、如果沒有分組的正則是返回的正則匹配,分組返回的是分組匹配而非整個正則匹配。

實例

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

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

#輸出結果:21313 1 58 4 8123 8435

實例擴展:

python3中函數說明:

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()的用法,可傳兩個參數;kk = re.compile(r’d+’)re.findall(kk,'one123')#[1,2,3]

其中,含()時要注意:

import restring='abcdefg acbdgef abcdgfe cadbgfe'#帶括號與不帶括號的區別#不帶括號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’]

到此這篇關于python中re.findall函數實例用法的文章就介紹到這了,更多相關python中re.findall函數的介紹內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 大足县| 赣榆县| 大田县| 满城县| 威远县| 台山市| 调兵山市| 改则县| 阿拉善盟| 黎川县| 荆门市| 毕节市| 新宁县| 孟州市| 镇原县| 黄梅县| 疏附县| 叶城县| 静宁县| 福贡县| 彭州市| 阿巴嘎旗| 佛学| 应城市| 房山区| 侯马市| 饶阳县| 雅江县| 鹿泉市| 西和县| 青浦区| 白山市| 新民市| 榆中县| 云龙县| 永修县| 若羌县| 怀来县| 普宁市| 丹寨县| 商城县|