Regex Railroad Diagram Generator
Turn any regular expression into a railroad (syntax) diagram. See groups, classes, alternation, and quantifiers visually.
Loading tool...
What is Regex Railroad Diagram Generator?
Regex Railroad Diagram Generator is a browser-based tool that turns any regular expression into a classic railroad (syntax) diagram. It parses the pattern with a real recursive-descent parser, then draws characters on the main rail, alternations as stacked branches, and quantifiers as skip and loop-back arcs β with every capture group numbered the way your regex engine numbers it. It is the fastest way to understand, review, and document complicated patterns, and it runs entirely offline.
Key Benefits
- Understand complex regex structure without mentally parsing it
- Review patterns faster: branches and loops are visually obvious
- Numbered capture groups match real match indices
- Clear syntax error messages pinpoint what is wrong
- Export theme-aware SVG for docs, wikis, and pull requests
Common Use Cases
- β’Decoding a gnarly regex inherited from legacy code
- β’Reviewing regex-heavy pull requests and validating intent
- β’Teaching or learning regex syntax visually
- β’Documenting validation patterns (emails, URLs, phone numbers) in wikis
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