Python 正则表达re模块之findall()详解

目录

一、re.findall函数介绍

二、代码如下

三、re.findall中正则表达式(.*?)

四、re.findall中参数re.S的意义

一、re.findall函数介绍

它在re.py中有定义:

def 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."""

    return _compile(pattern, flags).findall(string)

返回string中所有与pattern匹配的全部字符串,返回形式为数组。

findall()函数的两种表示形式

import re
kk = re.compile(r'\d+')
kk.findall('one1two2three3four4')
#[1,2,3,4]
 
#注意此处findall()的用法,

猜你喜欢

转载自blog.csdn.net/weixin_64974855/article/details/132613941