v1.2.0 Windows · Linux · macOS MIT

Regular expressions, explained.

RegexMate validates, matches, explains and draws regexes — with a versioned JSON contract, explicit exit codes and standalone binaries. Built for coding agents, and for the humans who review their work.

raco pkg install https://github.com/turinglambdaai/regexmate.git

Why RegexMate

Agent-native

One versioned JSON contract (regexmate/v1) across every command, absolute [start, end) spans, 1-based capture groups and exit codes that never lie. Drop it into any tool loop — no screenscraping, no guessing.

Plain-language explain

explain walks the parsed AST and narrates every part in English or 中文 — quantifiers, groups, lookarounds, unicode classes — so a pattern you inherited explains itself.

Railroad diagrams

graph renders any pattern to a clean SVG railroad diagram — for specs, pull requests and documentation. The diagrams on this page are generated by the tool itself.

One tool, five verbs

Everything works in human mode and JSON mode, in English and 中文.

regexmate
$ regexmate match '\d+' 'abc 123 def 456'
Found 2 match(es):
  at 4-7: "123"
  at 12-15: "456"

$ regexmate explain '(?:\d{2,4}|[a-z]+)(?=x)'
Pattern: (?:\d{2,4}|[a-z]+)(?=x)

Components:
  1. [group] (?:\d{2,4}|[a-z]+)
       ← Non-capturing group (?:...): Digit (\d) × {2,4} | Character class: [a-z] × +
  2. [lookaround] (?=x)
       ← Positive lookahead (?=...): Literal: x

$ regexmate replace '(\w+)@(\w+)' '\1 AT \2' 'a@b'
Replaced 1 occurrence(s).
Result: a AT b

$ regexmate graph 'ab(c|d)*' -o diagram.svg
SVG saved to: diagram.svg

See the pattern

Real output from regexmate graph — not a mockup.

Railroad diagram of the ISO date pattern
\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])
Railroad diagram of an email-ish pattern
[\w.+-]+@[\w-]+\.[\w.]{2,}

Built for the tool loop

Stable JSON envelope

{
  "schema":  "regexmate/v1",
  "command": "match",
  "ok":      true,
  "pattern": "(\\w+)@(\\w+)",
  "text":    "mail a@b",
  "count":   1,
  "matches": [{
    "value":  "a@b",
    "start":  5, "end": 8,
    "groups": [
      {"index": 1, "name": null,
       "value": "a", "start": 5, "end": 6},
      {"index": 2, "name": null,
       "value": "b", "start": 7, "end": 8}
    ]
  }]
}

Spans are absolute and [start, end). Absent groups are null — never missing keys.

Exit codes that mean something

0ok — match found / pattern valid / replacement done
1invalid regular expression
2usage error (bad flag, unknown command)
3valid pattern, zero matches / zero replacements

Scriptable to the core

# stdin in, JSON out — chain it anywhere
cat access.log | regexmate match '^(\d+\.\d+\.\d+\.\d+)' - --json

# exit code 3 = valid regex, no match
regexmate match 'ERROR' "$log" --json || code=$?

Text comes from an argument or stdin ('-'). NO_COLOR and REGEXMATE_LANG are honored; --lang switches output language.

MCP server

{
  "mcpServers": {
    "regexmate": {
      "command": "regexmate",
      "args": ["mcp"]
    }
  }
}

stdio JSON-RPC 2.0 (protocol 2024-11-05). Seven tools with input schemas: validate, match, explain, replace, graph, test, lint. Schemas are discoverable via tools/list.

The iteration loop

# assert against cases, get evidence
regexmate test '\d{4}-\d{2}-\d{2}' < cases.json

# static risk findings before shipping
regexmate lint '(a+)+' --strict
# exit 3: nested-quantifier — ReDoS risk

regexmate schema # contract, self-described

test asserts positives and negatives with per-case reasons; lint finds catastrophic backtracking, dead branches and shadowed alternatives — --strict turns findings into a CI gate.

Install

Standalone binary

Grab a release from GitHub — a single executable plus bundled runtime libraries. No Racket installation needed, and regexmate update keeps it current.

Releases

Racket package

Already running Racket? Install straight from the repository:

raco pkg install https://github.com/turinglambdaai/regexmate.git

From source

Clone, compile and produce your own binary in three commands (Racket 9.x):

git clone https://github.com/turinglambdaai/regexmate
cd regexmate && raco make main.rkt
racket run-tests.rkt && raco exe -o regexmate main.rkt

Roadmap

next Desktop GUI on the same core (railroad diagrams, live match table, explain pane)
later deeper lint rules: possessive quantifiers analysis, cross-engine portability checks
later Package-manager distribution (Homebrew, winget, AUR)