regex-mcp
Enables testing, explaining, debugging, and generating regular expressions directly within editors like Claude Code, Cursor, and VS Code Copilot, without leaving the editor.
README
regex-mcp
MCP server for testing, explaining, debugging, and generating regular expressions. Works with any MCP client — Claude Code, Cursor, VS Code Copilot, Windsurf, and more.
Never leave your editor for regex again.
Features
- Test — Run patterns against text with highlighted matches, capture groups, and coverage stats
- Explain — Token-by-token breakdown with nested group indentation
- Validate — Syntax checking with common pitfall warnings (greedy traps, anchor issues, unescaped dots)
- Replace — Find and replace with capture group references ($1, $2)
- Debug — Visual match markers with smart hints when patterns fail (case, anchors, whitespace, multiline)
- Generate — Natural language to regex for 25+ common patterns (email, URL, UUID, date, phone, etc.)
Install
Claude Code
claude mcp add @muhammadalishahzad/regex-mcp -- npx -y @muhammadalishahzad/regex-mcp
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"regex": {
"command": "npx",
"args": ["-y", "@muhammadalishahzad/regex-mcp"]
}
}
}
Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"regex": {
"command": "npx",
"args": ["-y", "@muhammadalishahzad/regex-mcp"]
}
}
}
VS Code Copilot
Add to .vscode/mcp.json:
{
"servers": {
"regex": {
"command": "npx",
"args": ["-y", "@muhammadalishahzad/regex-mcp"]
}
}
}
Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"regex": {
"command": "npx",
"args": ["-y", "@muhammadalishahzad/regex-mcp"]
}
}
}
Tools
regex_test
Test a pattern against input text. Returns highlighted matches, positions, capture groups, and coverage stats.
Pattern: \d+
Input: "Order #123 has 4 items at $99.50"
Found 4 matches (8 chars, 25.0% of input)
Highlighted: Order #[123] has [4] items at $[99].[50]
Match 1:
Text: "123"
Position: 7–10
Length: 3
Match 2:
Text: "4"
Position: 15–16
Length: 1
regex_explain
Token-by-token breakdown with group indentation for nested patterns.
Pattern: (?:https?://)([\w.-]+)(?:/(\w+))?
Breakdown:
(?: → start non-capturing group
h → literal 'h'
t → literal 't'
t → literal 't'
p → literal 'p'
s → literal 's'
? → optional (zero or one)
: → literal ':'
/ → literal '/'
/ → literal '/'
) → end group
( → start capture group
[\w.-] → any character in [\w.-]
+ → one or more times
) → end group
(?: → start non-capturing group
/ → literal '/'
( → start capture group
\w → any word character (a-z, A-Z, 0-9, _)
+ → one or more times
) → end group
) → end group
? → optional (zero or one)
regex_validate
Check syntax and detect common pitfalls.
Pattern: ^.*foo.bar$
Flags: g
Valid regex pattern.
Flags:
g — global — find all matches
Warnings (3):
1. Unescaped '.' matches ANY character. Did you mean '\.'?
2. '.*' is greedy — it matches as much as possible. Consider '.*?'
3. Using anchors (^/$) with global flag (g). Add 'm' for per-line matching.
regex_debug
Visual debugging with smart hints when patterns don't match.
Pattern: /^Hello/g
Input: "hello world" (11 chars)
Result: No matches.
Hints:
1. Case mismatch: With the 'i' flag, the pattern matches 1 time(s).
When matches are found, shows visual markers:
Found 2 matches:
"Error on line 42: timeout. Error on line 99: crash."
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
Match 1 [0–15]: "Error on line 42"
Context: [Error on line 42]: timeout. Err...
Match 2 [27–52]: "Error on line 99: crash."
Context: ...timeout. [Error on line 99: crash.]
regex_replace
Find and replace with capture group support.
Pattern: (\w+), (\w+)
Input: "Doe, John"
Replacement: $2 $1
Replacements: 1
Before:
Doe, John
After:
John Doe
regex_generate
Generate regex from natural language descriptions. Supports 25+ common patterns.
Description: "email address"
Best match:
Pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Description: Matches most common email address formats
Available categories: email, URL, IPv4, phone, date (ISO/US), time, hex color, UUID, number, decimal, HTML tag, credit card, ZIP code, MAC address, slug, camelCase, snake_case, password validation, JSON key, Markdown link, file extension, semver, and more.
Development
git clone https://github.com/MuhammadAliShahzad/regex-mcp.git
cd regex-mcp
npm install
npm run build
Test with the MCP Inspector:
npm run inspector
Run the server directly:
node build/index.js
How it works
regex-mcp runs as a local stdio process — no network calls, no API keys, no LLM dependencies. All regex operations use the native JavaScript RegExp engine. Pattern explanation uses a built-in tokenizer, not AI.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。