| import re |
| re.findall() 查询到所有符合的 |
| re.search |
| re.match |
| re.compile |
| flags 修改正则的匹配规则 |
| |
| 特殊符号 |
| |
| "." 除换行符外的任意字符 |
| "^" 匹配开头 |
| "$" 匹配结尾 |
| "*" 重复前一个字符0或尽可能多次 |
| "+" 重复前一个字符1或尽可能多次 |
| "?" 重复前一个字符0或1次 |
| *?,+?,?? 非贪婪模式 |
| {m,n} 匹配前一个字符m~n次,贪婪模式 |
| {m,n}? {m,n}的非贪婪模式,等同于{m} |
| "\\" 转义\ |
| [a-z] 匹配a-z |
| [^a-z] 匹配非a-z |
| A|B 匹配A或B |
| (...) 分组,可以在后面取回 |
| (?aiLmsux) Set the A, I, L, M, S, U, or X flag for the RE (see below). |
| (?:...) Non-grouping version of regular parentheses. |
| (?P<name>...) 设置命名分组 |
| (?P=name) Matches the text matched earlier by the group named name. |
| (?#...) A comment; ignored. |
| (?=...) Matches if ... matches next, but doesn't consume the string. |
| (?!...) Matches if ... doesn't match next. |
| (?<=...) Matches if preceded by ... (must be fixed length). |
| (?<!...) Matches if not preceded by ... (must be fixed length). |
| (?(id/name)yes|no) Matches yes pattern if the group with id/name matched, |
| the (optional) no pattern otherwise. |
| |
| \number 匹配分组内容. |
| \A 只匹配开头,类似^ |
| \Z 只匹配结尾,类似$ |
| \b Matches the empty string, but only at the start or end of a word. |
| \B Matches the empty string, but not at the start or end of a word. |
| \d 匹配数字,等价于 [0-9] |
| \D 匹配非数字,等价于 [^\d]. |
| \s 匹配所有空格,等价于 [ \t\n\r\f\v] |
| \S 匹配所有非空格,等价于[^\s]. |
| \w 匹配字符数字下划线,等价于 [a-zA-Z0-9_] |
| \W Matches the complement of \w. |
| \\ 匹配\ |
| |
| |
| |
| group(0) 打所有分组信息 |
| group(1) 打一个分组信息 |
| group('name') 打印命名分组名称为name的内容 |
| |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏