Regex Lab

io.github.basitalisandhuv0.1.1更新于 Oct 5, 2026

Test regular expressions in a timeout-guarded worker, explain them, find catastrophic backtracking.

概览

AI 生成的概览

让助手用样本测试 JavaScript 正则表达式、逐项解释模式,并检查是否存在灾难性回溯。

功能
提供三个处理 JavaScript(V8)正则表达式的工具。test_regex 用模式和标志匹配最多 50 个样本字符串,返回每个匹配的偏移、文本、编号与命名分组,以及可选的替换预览。explain_regex 逐项说明字面量、字符类、转义、锚点、分组、环视、量词和分支,并给出捕获组数量和标志含义。check_redos 报告嵌套无界重复、重复下的重叠分支等静态问题,再用定时探测确认或排除风险。
适用场景
适合在编写、调试或审查正则表达式时使用,需要匹配细节、通俗解释或快速排查易导致 ReDoS 的模式。在重视正则正确性与安全性的编辑器或编码流程中较为实用。
运行要求
以 npm 包形式通过 stdio 在本地运行,通常用 npx 启动;也发布了 Docker 镜像 ghcr.io/basitalisandhu/mcp-regex-lab:0.1.1。npm 方式需要 Node.js。未声明认证、环境变量、请求头、网络访问或本地文件访问。
安装前请注意
执行在 worker 线程中进行,超时后会被终止,且超时前完成的样本仍会返回,因此结果可能不完整。语法遵循 V8;PCRE、RE2 和 Python 在占有量词、后行断言等处存在差异。README 指出,未发现问题和平坦的耗时只是证据,并不能证明模式安全。请固定包版本,以免更新改变实际运行内容。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Regex Lab,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

regex-lab MCP server

Tests JavaScript regular expressions against sample strings, explains a pattern construct by construct, and looks for catastrophic backtracking. Every execution runs in a worker thread that is terminated when it exceeds the timeout, so a pathological pattern cannot hang the server.

Part of dev-mcp-servers. Stdio transport only; the server never opens a port.

Tools

ToolInputWhat it returns
test_regexpattern, flags?, samples[] (up to 50 of 20 000 chars), replacement?, timeout_ms? (50 to 10 000, default 2000)Every match per sample with offsets, text, numbered and named groups (with offsets), optional replace preview. Samples finished before a timeout are still returned.
explain_regexpattern, flags?Indented description of literals, classes, escapes, anchors, groups, lookarounds, quantifiers and alternation, plus the capturing group count and flag meanings.
check_redospattern, flags?, probe? (default true), timeout_ms?Static findings (nested unbounded repeats, overlapping alternatives under a repeat, adjacent overlapping repeats) with a probe character each, then timed runs against crafted inputs of growing length to confirm or clear the pattern.

Install

Claude Code:

bash
claude mcp add regex-lab -- npx -y @basitalisandhu/[email protected]

Add -s user to make it available in every project. Any client that reads .mcp.json (Claude Code, Claude Desktop, Cursor):

json
{  "mcpServers": {    "regex-lab": {      "command": "npx",      "args": ["-y", "@basitalisandhu/[email protected]"]    }  }}

Pin the version as shown so that an update to the package cannot change what runs in your editor without you noticing. From a checkout, use "command": "node", "args": ["<path>/packages/regex-lab/dist/index.js"] after npm install && npm run build at the repository root.

What it touches

  • Network: None.
  • Local files: None.
  • Telemetry: none.

Notes

  • Syntax follows V8 (Node.js). PCRE, RE2 and Python differ in places such as possessive quantifiers and lookbehind.
  • g and d flags are added automatically when matching; the replacement preview uses the flags you gave.
  • No findings and flat timings are evidence, not proof, that a pattern is safe.

Build and test

bash
npm install        # at the repository rootnpm run build -w @basitalisandhu/mcp-regex-labnpm test -w @basitalisandhu/mcp-regex-lab

Tests use node:test and the SDK's in-memory transport; they do not reach the network.

Licence

MIT. See LICENSE.

来源:packages/regex-lab/README.md,提交 58c8c95

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v0.1.1最新Oct 5, 2026