1-Python - re

about

re.findall

re.search

re.match

re.matchre.search用法一致,不不同的是re.match自带^效果。

分组

匿名分组

有名分组

取消分组优先

常见示例

匹配

pattern = r'^[-+]?[0-9]*\.?[0-9]+$' 
print(bool(re.match(pattern, 你的字符串)))

匹配手机号

import re
print(re.match(r'^1[3-9]\d{9}$', '18211101111'))

that's all
posted @ 2023-09-01 14:30  听雨危楼  阅读(39)  评论(0编辑  收藏  举报