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

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

python中re.findall函數實例用法

瀏覽:2日期: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 編程
相關文章:
主站蜘蛛池模板: 铁岭县| 凤阳县| 德保县| 麻阳| 拉萨市| 汪清县| 定边县| 景洪市| 师宗县| 兴宁市| 淅川县| 张掖市| 平原县| 长宁县| 苍溪县| 蒙山县| 府谷县| 长治县| 庆元县| 哈巴河县| 中牟县| 南雄市| 绥阳县| 红原县| 黄山市| 同江市| 玛纳斯县| 宜州市| 巴南区| 如皋市| 成安县| 鄂伦春自治旗| 苍梧县| 芷江| 五大连池市| 平阴县| 北流市| 通渭县| 舟曲县| 高台县| 都江堰市|