RegexPal
A real regex tester and toolkit for the terminal. Test patterns against text, find matches in files with highlighted output, perform replacements, extract capturing groups, and get human-readable explanations of regex syntax.
Commands
| Command | Description |
|---|
| INLINECODE0 | Test if a regex matches text — reports full match, partial match, groups, and named groups |
| INLINECODE1 |
Find all matches in a file — highlights matches in red, shows line numbers and match count |
|
regexpal replace <pattern> <replacement> <file> | Replace all matches in a file and output to stdout. Supports backreferences (
\1,
\2) |
|
regexpal extract <pattern> <file> | Extract capturing groups from all matches in a file — shows each group value per match |
|
regexpal explain <pattern> | Break down a regex pattern — lists character classes, groups, tokens, and quantifiers |
Requirements
- -
python3 (uses re stdlib module)
Examples
CODEBLOCK0
RegexPal
一个真正的终端正则表达式测试工具包。可对文本进行模式测试、在文件中高亮显示匹配结果、执行替换操作、提取捕获组,并提供正则表达式语法的可读解释。
命令
| 命令 | 描述 |
|---|
| regexpal test <模式> <文本> | 测试正则表达式是否匹配文本 — 报告完全匹配、部分匹配、捕获组和命名组 |
| regexpal match <模式> <文件> |
查找文件中的所有匹配项 — 以红色高亮显示匹配结果,显示行号和匹配计数 |
| regexpal replace <模式> <替换内容> <文件> | 替换文件中的所有匹配项并输出到标准输出。支持反向引用(\1、\2) |
| regexpal extract <模式> <文件> | 提取文件中所有匹配项的捕获组 — 显示每个匹配的组值 |
| regexpal explain <模式> | 分解正则表达式模式 — 列出字符类、组、标记和量词 |
系统要求
示例
bash
测试模式
regexpal test ^\d{3}-\d{4}$ 123-4567
在文件中查找电子邮件
regexpal match \w+@[\w.-]+ contacts.txt
替换版本号
regexpal replace v(\d+)\.(\d+) v\1.$((\\2+1)) changelog.md
从电子邮件中提取域名部分
regexpal extract (\w+)@(\w+\.\w+) emails.txt
理解复杂模式
regexpal explain (?<=@)[\w.-]+