python使用re模块操作正则表达式
一、概述
re
模块是python官方提供的正则表达式模块,一些常用的方法如下:
re.match(pattern, string, pos, endpos)
在string
中匹配pattern
规则,返回一个匹配对象。
re.search(pattern, string, pos, endpos)
在string
中查找第一个满足规则pattern
的字符串,返回一个匹配对象。
re.findall(pattern, string, pos, endpos)
查找所有满足规则pattern
的字符串,结果将返回一个元组。