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

本文介绍了Python的re模块中findall()函数的使用,详细解析了正则表达式(.*?)及其非贪婪匹配的概念,并探讨了参数re.S的作用,解释了如何在匹配过程中处理换行符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、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()的用法,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值