DevLab
.*
Regex⭐ Popularbeginner

Regex Explainer

break down a regex pattern into plain English with visual diagrams

By Bikram NathLast updated

Paste any regular expression to get a labeled plain-English breakdown of every token plus a railroad diagram showing the match path. For example, `^(?<year>\d{4})-\d{2}$` comes back with separate explanations for the start anchor, the named capture group, the digit quantifier, and the end anchor. The railroad diagram is what distinguishes this from a text-only description: it makes alternation branches and optional groups visually unambiguous.

Try it now — free, instant, no signup

What is Regex Explainer?

The tool parses a regex into its constituent tokens and returns a plain-English label for each one. Enter `(https?)://([^/]+)` and you see the first group described as "captures either 'http' or 'https'", the escaped slash identified as a literal character, and the second group explained as "everything that is not a forward slash". A railroad diagram renders alongside so you can trace the match path visually.

regex101 is the right choice when you need to test whether a pattern matches sample text. This tool fills a different gap: the regex already exists and the question is what it does. Regexper produces a visual railroad diagram but no accompanying text. The combination here is useful when you need to explain inherited or third-party regex in a code review comment without rewriting the pattern from scratch.

The parser uses the ECMAScript regex grammar, not PCRE. Patterns lifted from Python or PHP codebases often rely on `(?P<name>...)` named groups, possessive quantifiers like `a++`, or atomic groups `(?>...)`, none of which are valid ECMAScript syntax. Those will either produce a parse error or be silently misread. Convert named groups to `(?<name>...)` and strip possessive quantifiers before pasting.

When to use Regex Explainer

Audit a legacy route-matching regex before editing it by reading the full token-by-token breakdown before writing a single change.
Decode a Stack Overflow or LLM-generated pattern by seeing each quantifier, group, and anchor explained in plain English separately.
Prepare a code review comment with a plain-English summary of a regex that would otherwise demand lengthy inline documentation.

Frequently Asked Questions

Does the explainer support ECMAScript 2018 features like named capture groups and Unicode property escapes?
Named capture groups using `(?<name>...)` syntax are part of ECMAScript 2018 and should parse and display correctly. Unicode property escapes like `\p{Letter}` or `\p{Script=Greek}` are also ES2018 additions, but support depends on how the underlying parser implements that portion of the spec. If you see an unexpected parse error on a `\p{...}` pattern, the parser may not have reached that part of ES2018 yet. The `u` flag is required on the pattern for property escapes to be syntactically valid at all.
Why does the diagram show my quantifier as greedy even though I added `?` to make it lazy?
Greedy is the default behavior for `*`, `+`, `?`, and `{n,m}` in ECMAScript. Adding `?` directly after the quantifier (`*?`, `+?`, `??`, `{n,m}?`) switches to lazy mode, which matches as few characters as possible. If the diagram still reads greedy, verify that the `?` sits directly after the quantifier and has not been accidentally placed inside the preceding group. Some railroad renderers label quantifier symbols without indicating greedy versus lazy in the visual node; the accompanying text explanation should make that distinction explicit.
Can this explain lookbehind assertions, and will the explanation work correctly in older Safari?
Positive lookbehinds `(?<=...)` and negative lookbehinds `(?<!...)` were introduced in ECMAScript 2018. Safari only added lookbehind support in Safari 16.4, released March 2023. If the explainer uses the browser's native `RegExp` to validate the pattern as part of generating the breakdown, any Safari build older than 16.4 will throw a syntax error when the pattern is evaluated, even when the explainer is only parsing text. Lookaheads `(?=...)` and `(?!...)` carry no such compatibility risk and work in every browser.
My pattern uses a backreference like `\1`. Will the explainer identify which capture group it refers back to?
A numbered backreference like `\1` matches whatever text was captured by the first capture group earlier in the pattern. A complete explanation should cross-reference the backreference to the corresponding group rather than just labeling it "backreference 1". Named backreferences using `\k<name>` should similarly point to the named group. If the tool only labels the backreference without linking to the source group, you can identify the source manually by counting left parentheses left to right, skipping non-capturing groups `(?:...)`, lookaheads, and lookbehinds.
How does the railroad diagram here differ from what regexper.com produces?
Regexper generates SVG railroad diagrams from a regex pattern and nothing else. There is no accompanying prose; the diagram is the entire output. This tool pairs the railroad diagram with per-token plain-English labels, so you can read the structural flow in the diagram and a text description at the same time. That pairing resolves ambiguities that a diagram alone leaves open, for example distinguishing a character class `[ab]` from an alternation group `(a|b)`, which can render as visually similar railroad nodes depending on the implementation.

Related Tools