2
【笔记】Python3的Re包
source link: https://loli.fj.cn/2023/05/17/Python3%E7%9A%84Re%E5%8C%85/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
【笔记】Python3的Re包
2023-05-17
Python3的Re正则匹配包学习笔记
import re
匹配一次并返回匹配成功的字符串
从头开始匹配
res = re.match(正则表达式, 字符串).span()
从任意位置开始匹配
res = re.match(正则表达式, 字符串)
匹配一次并返回匹配成功的字符串位置
从头开始匹配
res = re.search(正则表达式, 字符串).span()
从任意位置开始匹配
res = re.search(正则表达式, 字符串)
匹配所有并返回匹配成功的字符串列表
res = re.findall(正则表达式, 字符串)
- 返回匹配成功的字符串所在下标的元祖,元祖中有2个元素,分别存储了开始位置和结束位置
res = re.findall(正则表达式, 字符串)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK