python re 模块,常用 方法 match、 findall、search 正则

re 模块 即RegExp

  1. re.macth(pattern, 字符串) 从头开始匹配,匹配第一个命中项
  2. re.search(pattern,字符串) 全局匹配,从前往后匹配,匹配第一个命中项
  3. re.findall(pattern, 字符串) 全局匹配,匹配全部命中项, 返回 列表 list
import re
re.match('Ares','Aresdfdsfds')
#  字符串前面带r的标记,表示字符串中转义符无效,就是字符串本身
re.findall(r'\d','8dhfdkjhf 3e33')   #  ['8', '3', '3', '3']

猜你喜欢

转载自blog.csdn.net/u013400314/article/details/131282754