regexlab-mcp
Runs regex patterns in JavaScript's RegExp engine via Node.js, returning matches and spans, comparing behavior with Python, converting Python/JavaScript patterns, and verifying compiled results.
Runs regex patterns in Python's re engine, returning matches, spans, groups, and Python-specific behavior, and supports comparing results against other regex engines.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@regexlab-mcp Test ^\d+$ against "123\n" in Python and JavaScript and explain any difference"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
regexlab-mcp
A regex lab for your AI agent: it RUNS the pattern in real engines instead of guessing.
Models write subtly wrong regexes: a $ that accepts a trailing newline, a \d that
matches Arabic digits, a (a+)+ that hangs your server, a (?P<name>...) pasted into
JavaScript. regexlab-mcp is an MCP server that gives the
agent somewhere to check. It runs your pattern in Python re, JavaScript's RegExp (through
node) and, if installed, the third-party regex module, each in a throwaway child process
with a hard timeout, and reports what actually happened.
What is different about it. A few regex MCP servers already exist (for example
regex-check-mcp, which also covers PCRE2 and
RE2, and rexact-mcp); I did not benchmark them
and they cover engines this one does not. The edge here is the combination: one server that
runs the same pattern side by side in several engines and flags disagreements, measures
ReDoS by timing adversarial input in a process that is killed at the budget (not only a static
guess), explains patterns with its own parser and says "not explained" instead of guessing,
translates between Python and JavaScript syntax and compiles the result in the target engine,
previews substitutions with each engine's own template rules, and generates test strings that
are verified by running them. It is pure Python with no dependency beyond mcp.
What it looks like
Real output (Python 3.12, node 24, regex 2026.9):
> test_regex pattern: ^\d+$ subject: "123\n"
case 1: '123\n'
python: 1 match
#1 [0:3] '123'
javascript: no match
regex: 1 match
#1 [0:3] '123'
=> ENGINES DIFFER on this case (see compare_engines for why)
> check_backtracking pattern: (a+)+$ engine: all
RISK: HIGH - catastrophic (exponential) backtracking CONFIRMED by running it.
1. [nested] `(a+)+` repeats something that contains the repeat `a+`, and what follows that
inner repeat can start with the same characters. ...
probe: python: TIMED OUT after 3.0s and was killed, at n~28; last completed n=24 took 1113 ms.
slow input: 'a' * 28 + '!'
> suggest_tests pattern: ^[A-Z]{2}\d{3,4}$
SHOULD MATCH (4 confirmed): 'AA000' 'AA0000' 'ZZ000' 'ZZ0000'
SHOULD NOT MATCH (25 confirmed): 'A000' 'AA00000' 'AA!00' 'aa000' ...
SURPRISES - expected NO match but the engine matched (4):
'AA000\n' matches 'AA000' at [0:5] ['AA000' with a trailing newline]
> convert_pattern (?P<y>\d{4})-(?P=y)\Z python -> javascript
pattern: (?<y>\d{4})-\k<y>(?![\s\S])
VERIFY: the converted pattern compiles in javascript v24.14.0.Related MCP server: RegexForge
Tools
Tool | What it does |
| All matches with |
| Token-by-token plain-English breakdown from the server's own parser: classes, greedy/lazy/possessive quantifiers, groups, lookaround, backreferences, anchors, flags, with engine-specific behaviour. Marks unsupported constructs |
| Static scan for nested/overlapping quantifiers plus a timed probe on crafted input, killed at the budget. Reports exponential vs polynomial, with an example slow input. |
| Compiles and runs one pattern everywhere, adds targeted variants (trailing newline, Unicode digits, non-ASCII word, emoji, Turkish case pairs) and lists the known semantic differences that apply. |
| Python to JavaScript and back (named groups, |
| Every substitution and the final text, using each engine's own template syntax ( |
| Should-match / should-not-match strings from the pattern's structure and mutations, all verified by running. Mutations that unexpectedly match are shown as SURPRISES. |
Install
Requires Python 3.10+. For the JavaScript engine install Node.js; for the
regex engine add the extra (regexlab-mcp[regex]). Tools report which engines were skipped.
Claude Code
claude mcp add regexlab -- uvx regexlab-mcp
# with the optional regex module:
claude mcp add regexlab -- uvx --from "regexlab-mcp[regex]" regexlab-mcpClaude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"regexlab": { "command": "uvx", "args": ["regexlab-mcp"] }
}
}Or pip install regexlab-mcp and run regexlab-mcp.
Try asking
"Write a regex for ISO dates and prove it works on these 10 inputs, in both Python and JavaScript."
"Is
^(\w+\s?)*$safe to run on user input? Check it.""Explain
(?<=\$)\d+(?:\.\d{2})?token by token.""This works in Python; make it work in JavaScript and tell me what changed."
"Preview this
re.subon my log line before I run it on the file.""Give me should-match and should-not-match tests for my phone number regex."
"Why does
^\d+$accept123\nin Python but not in the browser?"
Engines and limits
Engine | Needs | Notes |
| nothing | Python |
|
| V8 irregexp; |
|
| Possessive/atomic, |
Spans are [start:end) in Unicode code points for every engine (JavaScript's UTF-16 indices
are converted), so results are comparable. Limits: pattern 5000 characters, 100 cases,
200,000 characters of subject in total, 500 matches per case, timeout_s 0.2 to 30.
PCRE2, RE2 and other engines are not included. The explainer covers the common subset; recursion,
conditionals and \N{name} are reported as not explained. The ReDoS static scan is a heuristic
(it can flag shapes that are harmless, and the probe then clears them); "no finding" is evidence,
not proof.
Security
Regexes are untrusted input and can hang an engine for hours, which cannot be interrupted from inside the same process. So:
every run happens in its own child process (a fixed runner script, never
eval/execof user text); the pattern, flags and subject travel as JSON on stdin and are only ever passed tore.compile/new RegExpas data;no shell is used anywhere; the argument vector is fixed by the package;
a hard timeout kills the whole process tree (POSIX process group, Windows Job Object plus
taskkill /T); a test proves a grandchild process dies too;memory: 1 GiB address-space cap in the Python runner on Linux, a 1 GiB Job Object limit on Windows,
--max-old-space-size=256for node. macOS has no enforceable address-space limit, so there only the timeout and the input caps protect you;subject size, case count, match count, pattern length and captured output are all capped.
The server reads no files and opens no network connections.
Development
uv sync --extra test
uv run pytest tests -v
uv run --with ruff==0.16.0 ruff check src tests
uv run --with mypy==2.3.0 mypy --strict srcTests run real engines in real child processes. JavaScript tests are skipped when node is
missing and regex tests when the module is missing.
Want to build one yourself? regexlab-mcp-the-hard-way is a seven-module tutorial that builds a minimal version of this server step by step.
License
MIT
Available Tools
7 toolscheck_backtrackingA
Check a regex for catastrophic backtracking (ReDoS) by analysing AND timing it.
Two stages. Static: finds nested quantifiers like (a+)+, alternation with overlapping branches inside a loop, adjacent overlapping repeats like .., and unanchored leading repeats. Empirical: builds adversarial input for the worst suspects and times it in the real engine in a child process that is KILLED at the time limit. A pattern that hits the limit is reported as exponential, with an example slow input. Static suspicions the probe cannot reproduce are reported as unconfirmed; "no finding" is evidence, not proof.
engine: "python" (default), "javascript", "regex", or "all" for every available engine (V8 and Python's re have different optimisations, so results can differ). timeout_s: time budget per probe run, 0.2-30 (default 3).
Inputs: pattern (required), flags, engine, timeout_s. Returns: result
compare_enginesA
Run one pattern in every available engine and explain where they differ.
Reports whether the pattern compiles in each engine (named-group syntax (?P vs (?, \A \Z, inline flags, atomic groups, lookbehind width, \p{..}), runs your subject plus targeted variants (trailing newline, Unicode digits, non-ASCII word, emoji, Turkish case pairs) in all engines, and lists the known semantic differences that apply to this pattern ($ and trailing newline, Unicode-aware \d \w \b, dot and line terminators, case folding). Use it when a regex has to behave the same in Python and JavaScript.
Inputs: pattern (required), subject (required), flags, timeout_s. Returns: result
convert_patternA
Translate a regex between Python and JavaScript syntax, with explicit warnings.
Handles named groups and named backreferences, \A \Z and $ (using exact lookaround equivalents), inline global flags, verbose mode, {,n}, \U and \u{...} escapes, [^] and [], and the g/y/u flags. Things with no equivalent (atomic groups, possessive quantifiers, \p{..} in Python re, POSIX classes, recursion) are left unchanged and listed as WARNINGS. Differences that cannot be fixed syntactically (Unicode-aware \d \w vs ASCII-only) are listed too. The result is compiled in the target engine to prove it is at least valid; run test_regex or compare_engines to prove it is equivalent.
from_engine / to_engine: "python", "javascript" (or "js"), "regex". flags: flags of the source pattern; the converted flags are returned.
Inputs: pattern (required), to_engine (required), from_engine (required), flags, +1 more. Returns: result
explain_regexA
Explain a regex token by token in plain English, using this server's own parser.
Covers literals, escapes, classes, quantifiers (greedy, lazy, possessive), groups
(capturing, named, non-capturing, atomic), lookahead and lookbehind, backreferences,
anchors and inline flags, and says how each construct behaves in the chosen engine
(for example Python's $ before a trailing newline, or JavaScript's ASCII-only
\d). Constructs it does not model (recursion, conditionals, \N{...}) are marked
"NOT EXPLAINED" rather than guessed. Syntax errors are reported with the position.
Engine-specific syntax that the engine would reject is flagged as ERROR.
engine: "python" (default), "javascript" or "regex" (syntax dialect only; this tool does not need the engine installed). flags: same letters as test_regex; they change the explanation (m, s, a, x, ...).
Inputs: pattern (required), flags, engine. Returns: result
replace_previewA
Preview a regex substitution: every match, what it becomes, and the final text.
The replacement is expanded by each engine's own template rules, so the preview shows what the code will really do. Python uses \1, \g<1> and \g; JavaScript uses $1, $, $&, $` , $' and $$. If the replacement uses the other language's syntax (a common bug: "$1" in Python is literal text) a WARNING says so, and differing results between engines are called out.
engines: any of "python", "javascript" (or "js"), "regex"; default all available.
Inputs: pattern (required), subject (required), replacement (required), flags, +3 more. Returns: result
suggest_testsA
Generate should-match and should-not-match test strings for a regex, verified by running.
Builds examples from the pattern's structure (each alternative, quantifier minimum
and maximum, class boundaries) plus mutations (deleted or replaced characters, junk
prefix/suffix, trailing newline, case swap, off-by-one repeat counts), then RUNS all of
them in the real engine. Only confirmed examples are listed as tests. Mutations that
unexpectedly still match are listed as SURPRISES - they often expose a missing anchor,
a $ that accepts a trailing newline, or a class that is too broad. Uses search
semantics (match anywhere), and says when the pattern is not anchored.
engine: "python" (default), "javascript" or "regex" (must be available).
Inputs: pattern (required), flags, engine, timeout_s. Returns: result
test_regexA
Run a regex against text in REAL engines and report every match.
Use this to check any regex before telling the user it works. For each engine you get all matches (global search) with [start:end) spans in Unicode code points, the numbered and named capture groups, and a flag when engines disagree.
pattern: the regex source, exactly as it would appear in code (no delimiters, no extra string escaping). subject: one text, or a list of texts; each list item is a separate case. flags: letters: i ignore case, m multiline, s dot matches newline, x verbose and a ASCII classes (Python only), u unicode, v unicodeSets and y sticky (JavaScript only). g is implied. engines: any of "python", "javascript" (or "js"), "regex". Default: every engine available on this machine; unavailable ones are reported, not silently skipped. timeout_s: hard limit (0.2-30). A run that exceeds it is killed and reported as a catastrophic-backtracking case. max_matches: cap per case (max 500). Limits: pattern 5000 chars, 100 cases, 200k characters of subject in total.
Inputs: pattern (required), subject (required), flags, engines, +2 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a clearly stated, distinct job: testing, explaining, ReDoS analysis, cross-engine comparison, syntax conversion, substitution preview, and test generation. Minor overlap exists because test_regex already reports engine disagreements and killed timeouts, blurring its boundary slightly with compare_engines and check_backtracking, but the descriptions explicitly cross-reference when to use which.
All seven tools follow a strict snake_case verb_noun convention (test_regex, explain_regex, check_backtracking, compare_engines, convert_pattern, replace_preview, suggest_tests). The verb choice is also semantically meaningful and consistent across the set.
Seven tools is well within the ideal 3-15 range for a regex workbench and each tool covers a genuinely different stage of the regex lifecycle. Nothing appears redundant or thin.
The surface covers validation, explanation, performance safety, portability, conversion, substitution, and test generation—essentially the full regex workflow. Minor gaps remain, such as no explicit tool to list available engines/capabilities or to benchmark raw pattern throughput, but agents can work around these via test_regex output.
Related MCP Connectors
Run regexes on real engines (JavaScript, RE2/Go) against test strings, and prove ReDoS safety.
Execution platform for AI agents on Firecracker microVMs in the EU. Interactive Linux sandboxes with root, templates for Python, Node.js, Go, Rust and a headless browser, public HTTPS URLs. Background jobs that outlive the connection, batches of up to 1,000 jobs with dependencies, hard cost caps reserved up front, execution receipts with SHA-256, log digests that fit the context. IPv4, dual-stack or IPv6-only with its own public address, allowlists or no network. WASI runtime for small tasks. Idle sandboxes sleep and keep their files. Also REST API, Python SDK and LangChain.
Beta code sandbox for agents. Run Python or JavaScript with no network and a 30 s timeout.
JSON/YAML, regex, diff, JWT, SQL dialects — the keyless millisecond ops an agent needs mid-task.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides sandboxed code execution for AI agents with support for Python, JavaScript, and shell commands. Includes comprehensive safety features like destructive pattern blocking, timeout protection, and restricted file access for secure production use.28 PyPIMIT
- FlicenseNot gradedqualityCmaintenanceRegexForge gives AI agents a reliable way to get a regex without asking an LLM to hallucinate one. Pass in labeled examples (strings that should match, strings that shouldn't) plus an optional description; get back the regex, a proof matrix showing it handles every example, and a backtracking-risk audit flagging catastrophic-backtracking patterns. Pure symbolic synthesis over a template bank with-
- AlicenseAqualityDmaintenanceProvides tools to test regex patterns for correctness, performance (ReDoS), and memory usage, and suggests safe rewrites. Enables LLMs to iterate on regex generation with verifiable feedback.9MIT
- AlicenseAqualityDmaintenanceEnables AI agents to explain regex patterns in plain English and statically assess ReDoS risk before shipping, without executing the pattern or requiring an API key.2MIT