agentleFS
28672032962867203296/hermes-agent/skills/software-development/regex-master/SKILL.md

regex-master

Skill0 starsChanged 3 months agoMITView on GitHub

正则表达式速查:元字符、分组、断言、Pythonre模块、常用模式.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

正则表达式速查

借鉴 ziishaned/learn-regex (46k⭐)。

基础元字符

符号含义示例
.任意字符(除换行)h.t → hat, hit, hot
*前一个字符0次或多次ab*c → ac, abc, abbc
+前一个字符1次或多次ab+c → abc, abbc
?前一个字符0或1次colou?r → color, colour
{n}恰好n次a{3} → aaa
{n,}至少n次a{2,} → aa, aaa, aaaa
{n,m}n到m次a{2,4} → aa, aaa, aaaa
^行首^Hello
$行尾world$
\d数字 [0-9]\d+ → 123
\w单词字符 [a-zA-Z0-9_]
\s空白字符
\D非数字
\W非单词字符
\S非空白

字符类

[abc]      a或b或c
[^abc]     不是a、b、c
[a-z]      a到z
[0-9]      0到9
[a-zA-Z]   所有字母

分组与引用

(cat|dog)     cat或dog
(ha)+         ha, haha, hahaha
\1            引用第一个分组

断言(不消耗字符)

(?=...)    正向先行断言: 后面是...
(?!...)    负向先行断言: 后面不是...
(?<=...)   正向后行断言: 前面是...
(?<!...)   负向后行断言: 前面不是...

\w+(?=@)   匹配 @ 前面的用户名
(?<=\$)\d+ 匹配 $ 后面的数字

Python re 模块

import re

# 搜索(返回匹配对象或None)
m = re.search(r'\d+', 'abc123def')
m.group()  # '123'

# 查找所有(返回列表)
re.findall(r'\d+', 'a1b2c3')  # ['1', '2', '3']

# 替换
re.sub(r'\s+', ' ', 'a   b  c')  # 'a b c'

# 分割
re.split(r'[,;]', 'a,b;c')  # ['a', 'b', 'c']

# 编译(重复用更快)
pattern = re.compile(r'\d+')
pattern.findall('a1b2c3')

常用模式

# 邮箱(宽松版)
r'[\w.+-]+@[\w-]+\.[\w.-]+'

# 手机号(中国)
r'1[3-9]\d{9}'

# 身份证
r'\d{17}[\dXx]'

# URL
r'https?://[\w./-]+'

# IP 地址
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'

# 中文
r'[\u4e00-\u9fff]+'

# 提取引号内容
r'"([^"]*)"'
r"'([^']*)'"

# 去除 HTML 标签
re.sub(r'<[^>]+>', '', html)

标志

re.IGNORECASE  # 忽略大小写
re.MULTILINE   # ^$ 匹配每行首尾
re.DOTALL      # . 匹配换行
re.VERBOSE     # 允许注释和空白

# 组合
re.search(r'hello', text, re.IGNORECASE | re.MULTILINE)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.