好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python findall函数如何匹配字符串

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)

以上就是Python findall函数匹配字符串的方法,希望对大家有所帮助。 更多Python学习指路: python基础教程

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

查看更多关于Python findall函数如何匹配字符串的详细内容...

  阅读:24次