首页 Python通用模块视频教程 Python re模块常用API方法使用入门
pay pay

Python re模块常用API方法使用入门

日期: 五月 4, 2023, 10:07 a.m.
阅读: 210
作者: Python自学网-村长

摘要: Python re模块常用API方法使用入门

import re
# https://tool.oschina.net/regex/
# 记不住,写不好,看不懂,但是必须会
# str = 'abcd'
# pattern = 'ab'
# res = re.match(pattern, str)  # 返回值有None表示没有匹配成功,re.Match对象表示有匹配结果
# print(res)  # <re.Match object; span=(0, 2), match='ab'>
# print(res.group())  # 返回匹配成功的字符串ab
#
# print(re.findall(pattern, str))  # ['ab']



str = '32222222222333333'
pattern = '\d*'
res = re.match(pattern, str)  # 返回值有None表示没有匹配成功,re.Match对象表示有匹配结果
print(res)  # <re.Match object; span=(0, 2), match='ab'>

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部