regex-mcp

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.

Category
Visit Server

README

regex-mcp

npm version License: MIT

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured