Railroad diagram
reads left → rightIn plain English
Test against text
live — matches highlight as you typeMatches and captured groups will appear here.
Search & replace
live — replaced text updates as you type
Runs the pattern above against the same subject text and previews the
result of replacing every match. Supports
$1 … $n (numbered groups),
$<name> (named groups),
$& (whole match),
$` (before), $' (after), and
$$ (a literal $).
What this tool does — and its honest limits
What it does. regex-railroad draws a JavaScript regular expression as a
railroad ("train-track") diagram: the picture you drop into a pull-request review, a runbook,
or a wiki page to explain a gnarly pattern to teammates. Alongside the diagram you get a
clause-by-clause plain-English reading, a live match tester, a find-and-replace preview, and
SVG/PNG export. It handles the ES2018+ syntax the archived Regexper (read-only since June 2018)
predates: named groups (?<year>\d+), lookbehind (?<=\$)\d+,
Unicode property escapes \p{L}, and the s flag.
When you'd use it. Any time reading a pattern matters more than running it:
reviewing a 60-character regex someone pasted into a diff, documenting a validation rule, or
checking what a replacement string with $<name> tokens actually produces
before you commit it.
Honest limits. It targets JavaScript regexes specifically — PCRE recursion,
atomic groups and possessive quantifiers are not JS syntax and are rejected, not approximated.
The parser follows the modern (u-flag) grammar even without flags, so it is
stricter than the browser's Annex-B legacy mode: web-legacy oddities like a bare
\xZZ falling back to a literal, quantified lookahead (?=a)*, ES2025
duplicate group names, and non-ASCII group names all error here even though native engines
accept some of them. Group nesting deeper than 500 levels throws an honest error instead of
crashing.
One safety caveat. The diagram and explanation never execute your
pattern — a ReDoS-shaped regex like (a+)+b is safe to diagram. The match tester and
replace preview, however, run the real engine in this tab: a catastrophic-backtracking pattern
such as (a+)+$ against a long run of as can freeze the page for
seconds. Subjects are capped at 100,000 characters and 10,000 matches, but no cap can interrupt
a single backtracking pass — test patterns you trust.