Start a project

Tool 56 of 100 · Code

Regex Railroad Diagram

See what a regular expression really does: every branch, optional part and loop drawn as a railroad diagram, with each piece explained in plain English.

Regex Railroad Diagram at a glanceIllustration: 1, A regular expression; 2, processed in your browser; 3, A railroad diagram.Regex Railroad Diagram</>1A regular expression3A railroad diagram2In yourbrowser
1 A regular expression 2 processed on your device 3 A railroad diagram

Regex Railroad Diagram

Pattern

Railroad diagram

Read left to right. Branches are alternatives (|), a track that jumps over a box makes it optional, and a track that loops back repeats it.

In words

Structure

SVG file

SVG (with its own styles)

01

What it does

Draws a regular expression as a railroad diagram with a plain-English explanation, and exports the SVG.

  • Parser for JavaScript regex syntax, including named groups
  • Branches, optional parts and repeats drawn as tracks
  • Lookarounds, backreferences and Unicode classes
  • Plain-English explanation of each part

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

An SVG diagram and an explanation, with a Copy and a Download button on every result.

  • Regex
  • Visualiser
  • SVG

Why it matters

Regular expressions are dense: a single line can hold alternatives, nested groups and greedy loops, and reading someone else's pattern is hard. A railroad diagram turns the pattern into a map you follow from left to right.

This visualiser parses the expression itself, rather than guessing, so the diagram matches how JavaScript reads it. Use it to review a pattern in a pull request, explain one in documentation, or find why a pattern matches more than you meant.

How it works

  1. InputA JavaScript regular expression
  2. In your browserParsed into a syntax tree
  3. OutputAn SVG diagram and a plain-English outline

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Understanding or reviewing a pattern someone else wrote.

By the numbers

How many steps the tool's explanation takes per exampleEmail: 16 steps from 40 characters; UK postcode: 18 steps from 38 characters; Hex colour: 10 steps from 22 characters; ISO date: 28 steps from 47 characters; Web address: 25 steps from 49 characters; Password rule: 21 steps from 38 charactersEmail16 steps from 40 charactersUK postcode18 steps from 38 charactersHex colour10 steps from 22 charactersISO date28 steps from 47 charactersWeb address25 steps from 49 charactersPassword rule21 steps from 38 characters
Counted from this tool's own parser: every group, alternative, repeat and character class becomes one step in the diagram and the plain-English outline, which is why a 40-character pattern can hide a lot of logic. Source: MDN: regular expressions.
Show the numbers as a table
PatternCharactersSteps
Email4016
UK postcode3818
Hex colour2210
ISO date4728
Web address4925
Password rule3821

How to use it

  1. Paste a regular expression (without slashes) and choose flags.
  2. Follow the diagram from left to right.
  3. Read the explanation of each part.
  4. Download the SVG for docs or a review.

FAQ

Which regex flavour is this?

JavaScript (ECMAScript 2024), including named groups, lookbehind and the u and v flags. Most PCRE patterns look the same.

Does it test matches?

No, it explains the structure. Use the Regex Tester to run a pattern against text.

Why is a loop drawn under the track?

That's the repeat: you can go round as many times as the quantifier allows. A bypass above means the part is optional.

Can I use the SVG in docs?

Yes. It's a self-contained SVG that works in GitHub READMEs and documentation sites.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk