Regex Railroad Diagram
Visualize a regular expression as a railroad diagram and read a plain-English, step-by-step explanation. Hover to link the two. Runs in your browser.
About the Regex Railroad Diagram
- Railroad diagram
- Shareable link
- Open in the Regex Tester
- Instant results
- 100% private — runs in your browser
- Free, no sign-up
This tool turns a regular expression into a railroad (syntax) diagram — the left-to-right “train track” view used in language grammars — and pairs it with a plain-English, step-by-step explanation of what the pattern matches. Hovering a piece of the diagram highlights the matching line of the explanation, and vice versa, so you can connect the symbols to their meaning.
Reading a regex left to right, each box is something the input must match; branches are alternatives (this OR that); a lane that skips over a box means it is optional; and a loop-back under a box means it can repeat. Seeing that structure visually makes a dense pattern like a date or an email validator far easier to understand — and to spot bugs in.
It complements the Regex Tester: the tester shows you what a pattern matches against sample text, while this shows you how the pattern is built. Everything runs in your browser; the expression never leaves your device.
How to use it
- Type or paste a regular expression into the box.
- Toggle any flags (g, i, m, s, u, y) — each is labeled with its meaning.
- Read the railroad diagram left to right; branches are alternatives, skip-lanes are optional, loops repeat.
- Hover a box in the diagram or a line in “How it reads” — the matching part highlights in both.
- Click “Test in Regex Tester →” to run the same pattern against sample text.
Reading the diagram
- Box
- A literal character, a class like [a-z], or a shorthand like \d.
- Branch (stacked lanes)
- Alternation — the input matches one of the lanes.
- Skip lane above
- The element is optional (0 or 1) or repeatable from 0.
- Loop below
- The element repeats; a label like “2–4×” shows the count.
- Dashed box
- A group — a capture (#1, or named) or a non-capturing group.
- followed by / preceded by
- A lookahead or lookbehind assertion.
Frequently asked questions
How is this different from the Regex Tester?+
The Regex Tester runs your pattern against sample text and highlights matches. This tool visualizes the structure of the pattern itself as a railroad diagram plus a written explanation — useful for understanding or reviewing a regex rather than testing inputs.
What does the hover highlighting do?+
Hovering a box in the diagram highlights the corresponding line in the “How it reads” list, and hovering a line highlights its part of the diagram — so you can map each symbol to its meaning.
Which regex syntax is supported?+
JavaScript-flavor regular expressions: literals, character classes, groups (capturing, named, non-capturing), alternation, quantifiers (including {n,m} and lazy variants), anchors, backreferences, and lookahead/lookbehind. An invalid pattern shows a parse error.
Is my expression sent anywhere?+
No. Parsing and rendering happen entirely in your browser with client-side JavaScript; the expression never leaves your device.
Works well with
Regex Railroad Diagram chains with these tools — send your result straight on:
Related tools
Case Converter
Convert text between camelCase, PascalCase, snake_case, CONSTANT_CASE, kebab-case, Title Case, and more — all at once, in your browser.
Diff Viewer
Compare two texts or code snippets side by side with line-level difference highlighting.
Image to Text (OCR)
Extract the text from a screenshot, photo, or scanned document with OCR — in 18 languages, entirely in your browser. Nothing is uploaded.
Markdown Editor
Write Markdown with a live GitHub-flavored preview, a table of contents, and one-click export to Markdown or HTML — entirely in your browser, nothing uploaded.
Mojibake Fixer
Repair garbled text where UTF-8 was misread as Windows-1252 — turn “café” back into “café” and “’” back into “’”. Runs entirely in your browser.
Regex Sample Generator
Generate example strings that match a regular expression, then send them straight into the Regex Tester. Every sample is verified to match — all in your browser.