RegexTester
v1.0.0正则表达式助手,支持匹配测试、提取所有匹配、分组捕获、文本替换及常用模式生成。
Security Scan
OpenClaw
Benign
high confidencePurpose & Capability
The name/description (regex tester) matches the included assets and behavior. The script implements matching, findall, groups, sub, and pattern generation as documented. No unrelated binaries or credentials are requested.
Instruction Scope
SKILL.md instructs the agent to run the local Python script (python3 script/main.py ...) which is appropriate. Some examples show shell substitutions like $(cat error.log) to feed file contents; this is a legitimate usage for testing but it references reading local files (which is expected for a tester). The instructions do not direct data to remote endpoints or ask for unrelated environment variables.
Install Mechanism
No install spec is present (instruction-only with an included script). Nothing is downloaded or written to disk by an installer, which minimizes install-time risk.
Credentials
No environment variables, credentials, or config paths are requested. The declared capabilities align with this: the tool operates on inputs passed on the command line or piped from files.
Persistence & Privilege
The skill is not always-included and does not request elevated persistence. It is user-invocable and allows normal autonomous invocation (the platform default), which is expected for a utility skill.
Assessment
This skill is coherent and appears to do only local regex processing. Things to consider before installing: (1) The tool processes text you pass to it—avoid feeding secrets or sensitive files unless you trust the runtime and local environment. Examples in SKILL.md that use shell substitution (e.g., $(cat error.log)) will cause the shell to read files on disk before invoking the script. (2) As with any regex tool, untrusted or pathological regular expressions can be CPU-intensive (ReDoS) if run against large inputs—avoid running untrusted complex patterns on very large files. (3) If you need network isolation or extra confidentiality, run the script in an isolated environment. Otherwise, the skill does not request credentials or perform network access and is internally consistent with its description.Like a lobster shell, security has layers — review code before you run it.
latest
正则表达式助手 (Regex Tester)
正则表达式测试与调试工具,帮助开发者快速验证正则表达式、提取匹配结果和执行替换操作。
技能目的
提供便捷的正则表达式测试环境,帮助用户:
- 验证正则表达式是否正确匹配目标文本
- 查看捕获分组的内容
- 执行替换操作并预览结果
- 获取详细的匹配信息
何时使用此技能
在以下情况下使用此技能:
- 需要测试或调试正则表达式
- 需要从文本中提取特定模式的内容
- 需要进行批量文本替换
- 需要了解正则表达式的匹配行为
- 需要生成常用正则表达式模式
功能特性
1. 基本匹配测试
测试正则表达式在目标文本中的匹配情况。
python3 script/main.py match "<正则>" "<文本>"
示例:
# 测试邮箱匹配
python3 script/main.py match "[\w.+-]+@[\w-]+\.[\w.-]+" "contact@example.com"
# 测试手机号匹配(中国大陆)
python3 script/main.py match "1[3-9]\d{9}" "13800138000"
2. 提取所有匹配
获取文本中所有匹配正则表达式的内容。
python3 script/main.py findall "<正则>" "<文本>"
示例:
# 提取所有URL
python3 script/main.py findall "https?://\S+" "访问 https://example.com 和 http://test.org"
# 提取所有数字
python3 script/main.py findall "\d+" "价格: 99, 数量: 100, 总计: 9900"
3. 分组捕获
查看正则表达式中的捕获分组内容。
python3 script/main.py groups "<正则>" "<文本>"
示例:
# 解析日志格式
python3 script/main.py groups "\[(.*?)\] \[(.*?)\] (.*)" "[2024-02-14] [INFO] 启动服务"
# 解析日期时间
python3 script/main.py groups "(\d{4})-(\d{2})-(\d{2})" "今天是2024-02-14"
4. 文本替换
使用正则表达式进行文本替换。
python3 script/main.py sub "<正则>" "<替换内容>" "<文本>"
示例:
# 隐藏手机号中间四位
python3 script/main.py sub "(\d{3})\d{4}(\d{4})" "\1****\2" "联系13800138000"
# 去除HTML标签
python3 script/main.py sub "<[^>]+>" "" "<p>你好<b>世界</b></p>"
5. 常用模式生成
生成常用场景的正则表达式模式。
python3 script/main.py pattern "<模式名称>"
支持的模式:
email- 邮箱地址phone- 中国手机号idcard- 中国身份证号ipv4- IPv4地址url- URL地址date- 日期 (YYYY-MM-DD)time- 时间 (HH:MM:SS)chinese- 中文字符username- 用户名 (字母数字下划线)password- 密码 (至少8位,包含字母和数字)
示例:
python3 script/main.py pattern email
python3 script/main.py pattern phone
参数说明
| 参数 | 说明 |
|---|---|
match | 测试基本匹配 |
findall | 提取所有匹配 |
groups | 查看分组捕获 |
sub | 执行替换操作 |
pattern | 生成常用模式 |
使用示例
场景 1: 验证输入格式
# 验证邮箱格式是否正确
python3 script/main.py match "[\w.+-]+@[\w-]+\.[\w.-]+" "user@company.com"
场景 2: 提取数据
# 从日志中提取所有错误代码
python3 script/main.py findall "ERROR:\s*(\w+)" "$(cat error.log)"
# 提取Markdown中的链接
python3 script/main.py findall "\[([^\]]+)\]\(([^)]+)\)" "[首页](https://example.com)"
场景 3: 数据清洗
# 统一日期格式
python3 script/main.py sub "(\d{4})/(\d{2})/(\d{2})" "\1-\2-\3" "2024/02/14"
# 去除多余空格
python3 script/main.py sub "\s+" " " "你好 世界"
场景 4: 查看正则分组
# 解析命令行参数
python3 script/main.py groups "--(\w+)=([^\s]+)" "--name=test --port=8080"
# 解析CSV格式
python3 script/main.py groups "([^,]+),([^,]+),([^,]+)" "张三,25,北京"
正则表达式语法速查
| 符号 | 说明 |
|---|---|
. | 匹配任意字符(除换行) |
\d | 匹配数字 |
\w | 匹配字母数字下划线 |
\s | 匹配空白字符 |
^ | 匹配行首 |
$ | 匹配行尾 |
* | 匹配0次或多次 |
+ | 匹配1次或多次 |
? | 匹配0次或1次 |
{n} | 匹配n次 |
{n,} | 匹配至少n次 |
{n,m} | 匹配n到m次 |
[abc] | 匹配a、b或c |
[^abc] | 匹配非a、b、c的字符 |
() | 捕获分组 |
(?:) | 非捕获分组 |
| ` | ` |
注意事项
- 特殊字符需要转义:
. ^ $ * + ? { } [ ] \ | ( ) - 使用
.*时注意贪婪匹配,可用.*?进行非贪婪匹配 - 捕获分组编号从1开始,
group(0)是整个匹配结果 - Python默认使用Unicode模式,可匹配中文等Unicode字符
目录结构
regex-tester/
├── SKILL.md # 技能说明文档(本文件)
├── script/
│ └── main.py # 主程序
└── tests/ # 测试用例
Comments
Loading comments...
