国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

python中re.findall函數實例用法

瀏覽:4日期: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 編程
相關文章:
主站蜘蛛池模板: 通海县| 绍兴县| 亳州市| 鄂托克前旗| 梁山县| 博客| 马公市| 衢州市| 内江市| 邯郸市| 绥滨县| 横峰县| 长汀县| 毕节市| 登封市| 阿荣旗| 汶川县| 嘉义县| 昌乐县| 台北市| 宿松县| 张掖市| 深泽县| 会同县| 大关县| 新郑市| 新干县| 肥城市| 前郭尔| 黎川县| 集贤县| 邛崃市| 临安市| 广德县| 临夏县| 蒙自县| 嘉黎县| 望江县| 安丘市| 太谷县| 青岛市|