首页 > 文章列表 > Python findall函数如何匹配字符串

Python findall函数如何匹配字符串

Python findall
175 2022-08-07

1、在字符串中找到正则表达式所匹配的所有子串,并返回一个列表,如果没有找到匹配的,则返回空列表。

2、语法为

findall(string[, pos[, endpos]])

参数

string : 待匹配的字符串。

pos : 可选参数,指定字符串的起始位置,默认为 0。

endpos :可选参数,指定字符串的结束位置,默认为字符串的长度。 查找字符串中的所有数字

实例

#A-Za-z
import re
dd = "重出123江湖hello的地方的,world"
result = ''.join(re.findall(r'[A-Za-z]', dd))
print(result)

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。