1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python 正则表达式 re.findall()方法

python 正则表达式 re.findall()方法

时间:2023-03-08 20:12:23

相关推荐

python 正则表达式 re.findall()方法

from 《Python 爬虫开发 从入门到实战》谢乾坤

pattern表示正则表达式,string表示原来的字符串,flags表示一些特殊功能的标志。

findall的结果是一个列表,包含了所有匹配到的结果。如果没有匹配到结果,就会返回空列表。

from 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, returna list of groups; this will be a list of tuples if the patternhas more than one group.如果模式中存在一个或多个捕获组,则返回组列表; 这将是一个元组列表,如果模式有一个以上的团体。Empty matches are included in the result.空匹配项包含在结果中"""return _compile(pattern, flags).findall(string)

如:

content_extract=re.findall('(.*?) (.*?) (.*?) (.*?) (.*?)\n',content)

参考文章:Python 正则表达式

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。