Regex Toolkit
Test, find, replace, explain, and validate regular expressions. Includes 25+ common named patterns. Pure Python, no dependencies.
Quick Start
CODEBLOCK0
Commands
| Command | Description |
|---|
| INLINECODE0 | Check if pattern matches. Shows first match position and groups. |
| INLINECODE1 |
Find all matches with positions and captured groups.
--json for JSON output. |
|
replace | Regex search-and-replace. Supports
\1 backreferences.
--count N limits replacements. |
|
explain | Break down a regex into plain-English explanation of each element. |
|
validate | Check if a regex pattern is syntactically valid. |
|
patterns | List built-in common patterns or show a specific one by name. |
Input Options
All matching commands accept: --text 'string', --file path, or piped stdin.
Flags
| Flag | Description |
|---|
| INLINECODE11 | Case-insensitive matching |
| INLINECODE12 |
^/
$ match line boundaries |
|
-s, --dotall |
. matches newline |
Built-in Patterns
Use by name instead of writing regex: email, url, ipv4, ipv6, phone-us, phone-intl, date-iso, date-us, time-24h, hex-color, mac-address, uuid, ssn, zip-us, credit-card, slug, semver, domain, hashtag, mention, markdown-link, html-tag, json-key, filepath-unix, filepath-win.
正则表达式工具包
测试、查找、替换、解释和验证正则表达式。包含25+常用命名模式。纯Python实现,无依赖。
快速开始
bash
测试模式
python3 scripts/regex_toolkit.py test \d+ --text abc 123 def
使用命名模式(邮箱、网址、IPv4、美国电话、UUID等)
python3 scripts/regex_toolkit.py findall email --text Contact hello@example.com or support@test.org
查找所有匹配项及其位置
python3 scripts/regex_toolkit.py findall \b\w{5}\b --file input.txt
搜索并替换
python3 scripts/regex_toolkit.py replace \bfoo\b -r bar --text foo bar foo
用通俗英语解释正则表达式
python3 scripts/regex_toolkit.py explain (?P
\d{4})-(\d{2})-(\d{2})
验证正则表达式语法
python3 scripts/regex_toolkit.py validate [a-z
列出所有常用模式
python3 scripts/regex_toolkit.py patterns --list
从标准输入读取
echo Call 555-1234 or 555-5678 | python3 scripts/regex_toolkit.py findall phone-us
命令
| 命令 | 描述 |
|---|
| test | 检查模式是否匹配。显示首个匹配位置和分组。 |
| findall |
查找所有匹配项及其位置和捕获组。使用--json输出JSON格式。 |
| replace | 正则表达式搜索替换。支持\1反向引用。--count N限制替换次数。 |
| explain | 将正则表达式分解为每个元素的通俗英语解释。 |
| validate | 检查正则表达式模式语法是否有效。 |
| patterns | 列出内置常用模式或按名称显示特定模式。 |
输入选项
所有匹配命令接受:--text 字符串、--file 路径或通过管道传入的标准输入。
标志
| 标志 | 描述 |
|---|
| -i, --ignorecase | 不区分大小写匹配 |
| -m, --multiline |
^/$匹配行边界 |
| -s, --dotall | .匹配换行符 |
内置模式
按名称使用,无需编写正则表达式:email、url、ipv4、ipv6、phone-us、phone-intl、date-iso、date-us、time-24h、hex-color、mac-address、uuid、ssn、zip-us、credit-card、slug、semver、domain、hashtag、mention、markdown-link、html-tag、json-key、filepath-unix、filepath-win。