regex-railroad
Live railroad diagram, plain-English explanation, match tester and replace preview for modern JS regexes (named groups, lookbehind, \p{…}). Runs entirely in your browser; exports SVG/PNG.
Test against text
live — matches highlight as you typeSearch & 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 $).
Railroad diagram
reads left → rightIn plain English
Matches
Matches and captured groups will appear here.
Runs entirely in your browser — nothing you type is ever sent anywhere. The page does load one cookieless pageview counter from stats.dankdev.com; it records the URL, never your pattern.
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 is capped at 500 levels: 500 nested groups parse and
diagram normally, and 501 stops with the explaining error Group nesting exceeds the
supported depth of 500 (deeper patterns would overflow the call stack) rather than a raw
stack overflow. Hand-written patterns almost never nest past depth 10, so the cap only bites on
machine-generated input.
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.