Regex Railroad Diagram Generator
Turn any regular expression into a railroad (syntax) diagram. See groups, classes, alternation, and quantifiers visually.
Loading tool...
Visualize a Regex as a Railroad Diagram
- Paste your pattern: Type or paste the regular expression into the pattern box β a URL-matching example is preloaded so you see a diagram immediately, and Reset brings it back anytime.
- Read the diagram: Follow the main rail left to right; branches show alternation, loop bands show quantifiers, and small pills mark group kinds such as named captures and lookaheads.
- Fix any parse errors: If the pattern cannot be parsed, an error names the offending character and position β correct it and the diagram redraws live as you type.
- Export the SVG: Press Copy SVG for the clipboard or Download SVG to save railroad-diagram.svg at the exact size shown by the dimensions label.
Key Features
- Full regex parser: literals, classes, ranges, escapes, and anchors
- Alternations drawn as stacked branches with clear routing lines
- Quantifiers *, +, ?, and {m,n} rendered as skip and loop-back arcs
- Capture groups numbered to match your match() group indices
- Lookaround and named groups labeled on the diagram
- One-click SVG copy or download for docs and PRs
Frequently Asked Questions
Which regex features does the diagram support?
Literals, character classes, alternation, anchors, escapes like \d and \b, all group kinds (capturing, non-capturing, named, lookahead, lookbehind), and quantifiers *, +, ?, {m,n} including lazy variants.
Why does the tool show an error instead of a diagram?
The parser reports the exact problem and position, such as an unclosed group or a trailing backslash, so you can fix the pattern directly. The diagram redraws live as soon as the pattern parses.
How do I get the diagram into documentation or a README?
Use Copy SVG to grab the raw markup or Download SVG to save railroad-diagram.svg. It is a standalone SVG that scales cleanly in markdown files, wikis, and slide decks.
Are my regex patterns uploaded anywhere?
No. Parsing and rendering happen entirely in your browser β nothing is sent to a server, so proprietary patterns stay on your machine.