Railroad diagrams · updates as you type
Regex Visualizer
How to read a railroad diagram
- Boxes are things to match: literal text, character classes such as digits or word characters, and anchors.
- A fork in the track is an alternation (
|): the string can take either branch. - A track that loops back is a repeat. A plain loop means one or more; a label such as “2–5 times” or “lazy” gives the exact rule.
- A track that bypasses a box makes it optional (
?,*). - Capturing groups are drawn as numbered frames, and named groups show their name. Lookarounds are frames captioned “followed by” or “preceded by”.
When a diagram beats reading the pattern
Diagrams shine on long patterns with nested groups, where it is easy to lose track of which ) closes which (. In the sample, you can see at a glance that the port and the path are both optional, and that only http, https and ftp are allowed before ://. The last line of the test text fails validation because mailto: is not one of those branches.
Diagrams also make reviews easier. A colleague who does not read regex fluently can still follow the tracks and spot a missing branch.
Every language, one picture
Switch the language in the top bar and the diagram is drawn from the pattern as that language writes it, while the compatibility banner warns about any feature the language lacks. Every pattern in the Pattern Library has its own diagram too.
Frequently asked questions
- Can I save the diagram as an image?
- The diagram is drawn as SVG in the page. You can take a screenshot, or print the page to PDF from your browser. There is no separate image download yet.
- Does the diagram show lookarounds?
- Yes. Lookahead and lookbehind are drawn as frames captioned “followed by”, “NOT followed by”, “preceded by” or “NOT preceded by”, so you can see that they check the text around a position.
- How is this different from Regexper?
- The idea is the same, a railroad diagram, but here it sits beside live matching, an explanation, the step debugger and code for 8 languages, and it redraws as you type.