Regex Explainer

Paste a regular expression and read a token-by-token explanation of what each part does.

Regular expression
Explanation
Runs locally in your browser

About the Regex Explainer

Reading someone else's regex is harder than writing your own. This explainer walks through a pattern token by token and describes each in plain words: anchors, character classes, quantifiers, groups (capturing, non-capturing, look-ahead and look-behind), escapes and alternation. The result is a table of the pattern's pieces and their meanings, which is usually enough to understand what it accepts and why.

Quantifiers cause most of the confusion, so they are spelled out individually: {2,} is two or more, {2,4} is two to four, ? makes the previous item optional, and a ? added after any quantifier makes it lazy. That last one matters more than it looks, because <.*> swallows an entire line of markup while <.*?> stops at the first closing bracket, and the explanation names greedy and lazy repetition separately so the difference is visible.

The usual reason to reach for it is inheriting a validation pattern in a form, a router or a log filter, and needing to know what it rejects before you dare change it. Coverage extends to the constructs found in the vast majority of real-world patterns; exotic syntax may be described in general terms. Once you know what a pattern claims to do, run it against real input in the Regex Tester, or turn it into a substitution with Regex Replace.

How to use

  1. Paste the pattern, with or without surrounding slashes.
  2. Read each token and its meaning.
  3. Test it against real text in the Regex Tester.

Common questions

Which syntax does it explain?
JavaScript-style regex, which shares its everyday syntax with most engines.
Does it explain look-behind?
Yes, positive and negative look-ahead and look-behind groups are labelled.
What about very unusual constructs?
They may be described generically. The Regex Tester shows their actual behaviour.