I gave my AI assistant a regex test bench

· 2 min read

Ask an AI assistant for a regular expression and it will hand you one that looks right. It did not run it. It did not check that it accepts your valid cases and rejects the invalid ones, that it cannot hang a server on a well-chosen input, or that it works in the engine you actually use. Rexact MCP closes that gap.

Three concrete failure modes

  1. Nobody tested it. The pattern ^\d{5}$ for a French postal code looks obvious. But does it accept 75001 and reject 7500 and 75 001? Until something runs it, nobody knows.
  2. It can hang. (a+)+$ is the textbook case of catastrophic backtracking: on a string of a characters ending in something else, run time blows up. That is the ReDoS risk, and an assistant that does not execute the pattern will not see it.
  3. It is not portable. A lookbehind such as (?<=\d)€ works in some engines and not in RE2, which supports neither lookbehind nor backreferences.

What Rexact MCP adds

Rexact MCP is an MCP server: a small program the assistant can call like a tool. It is free, MIT-licensed, and runs locally and offline, with no key or account. It exposes five tools:

Tool What it is for
verify_regex Runs the regex against your valid and invalid cases
check_redos Looks for catastrophic-backtracking patterns
explain_regex Explains the regex in plain words, piece by piece
check_compat Checks behaviour across several engines
generate_regex Generates a regex from a description

On the Rexact side, the engines covered are JavaScript, PCRE, Python, RE2, Java, .NET and grep.

Installing it

Requirement: Node.js 20 or later.

With Claude Code:

claude mcp add rexact -- npx -y rexact-mcp

With Claude Desktop, Cursor and similar clients, add this block to the mcpServers configuration:

{
  "mcpServers": {
    "rexact": {
      "command": "npx",
      "args": ["-y", "rexact-mcp"]
    }
  }
}

What using it looks like

Here is an example request, given as an illustration:

Write me a regex for a French postal code and check it with these cases: 75001 and 13008 valid; 7500, 75 001 and ABCDE invalid.

The assistant proposes a pattern, calls verify_regex with your five cases, and answers from the results rather than from how the pattern feels. Same idea for a regex you already have: “run this one through check_redos before I ship it”.

Privacy

No regex is sent to Rexact. Only generate_regex calls a model, using your own Anthropic key, so at your expense. The other four tools stay entirely local.

Where to go next