Skip to content
Jellykit

Regex Explainer and Railroad Diagram

Explains a JavaScript regular expression token by token in plain English and draws it as a railroad diagram you can follow.

  • Runs on your device
Loading tool

About Regex Explainer and Railroad Diagram

Paste a regular expression you did not write, or one you wrote months ago, and read what each part of it means: every literal, escape, character set, group, back-reference, quantifier, anchor and lookaround, nested the way the pattern nests them, with each flag explained as well.

Under the explanation the same pattern is drawn as a railroad diagram: branches for alternatives, loops for repetition and frames around groups. The pattern is read in JavaScript syntax and checked by your browser’s own engine, but it is never run against any text.

How it works

  1. Your browser’s JavaScript engine first checks the pattern and its flags, so a syntax error is reported with the engine’s own reason.
  2. The pattern is then taken apart into a tree with the regexp-tree parser, and every node of that tree is described in a sentence. Runs of plain characters are read together as one piece of text.
  3. The diagram is drawn from the same tree as an SVG image. It is left out, with a note, for a pattern of more than 300 parts or nested more than 24 levels deep; the explanation is still given in full.
  4. Nothing is matched or executed, and nothing is sent anywhere: the whole explanation happens on this page.

Questions

Which regular expression syntax does it explain?

JavaScript, as written in a /pattern/flags literal or passed to new RegExp(). Most of it is shared with other languages, but some features, such as possessive quantifiers or inline flags like (?i), belong to other engines and are reported as errors here.

Can I paste a pattern with its slashes and flags?

Yes. A pattern written as /pattern/flags is read as a literal: the flags after the last slash are added to the ones in the Flags box. Without slashes, the text is the pattern itself.

Does it support the v flag?

The v flag is explained, and a pattern that uses it is read as with the u flag. The set notation that only v allows, such as nested brackets, && and -- inside brackets, or \q{…}, is not explained yet; the tool says so instead of guessing.

Will it tell me whether my pattern is slow?

No. The pattern is never run, so this tool says nothing about how fast it matches. To try a pattern against text, use a regex tester.

How long can the pattern be?

Up to 2 KB. Every pattern within that size is explained in full; the diagram is drawn for patterns of up to 300 parts and 24 levels of nesting.

Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.