Reading a regex
A regex is a sequence of tokens, each with a job: literal characters match themselves, character classes ([a-z]) match one of a set, quantifiers (+ * ? {2,4}) say how many, anchors (^ $ \b) pin positions, and groups ((…)) bundle and capture. The explainer walks every token left to right and says what the engine will try to match at that spot.
Common patterns decoded
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$— a classic email pattern: start, one or more username chars, @, domain chars, a dot, 2+ letters, end.\d{2,4}[a-z]?— 2 to 4 digits followed by an optional lowercase letter.(https?:\/\/)?[^\s]+— optional http(s):// then any non-space run.
Tips
- Escape sequences (
\d \w \s \b \. \/) are explained as units — they're not two separate tokens. - Greedy vs lazy:
+matches as much as possible,+?as little as needed. - Lookahead
(?=…)checks ahead without consuming;(?!…)is the negative form. - The explainer works on the pattern syntax common to JS, Python, Java, Go, PCRE — flag letters like
i/m/sare noted when present.
Under the hood
explain() walks the pattern with tokenAt(), which recognises one construct at a time — an escape, a character class, a quantifier, a group, an anchor or a lookaround — and returns both the token length and a plain-language description. The loop advances by that length, so the explanation stays aligned with the source even when a construct spans several characters. escapeHtml() keeps angle brackets in the pattern from being rendered as markup.
Formats, sizes and other limits
This reads structure; it does not compile or run the pattern, and it does not build a full syntax tree — so scope questions (what exactly a quantifier applies to inside nested groups) are described in words rather than shown graphically. Invalid patterns are still tokenised, producing a confident-looking explanation of something that will not compile. Dialect differences such as PCRE-only escapes are described with common semantics, not your engine's.
Privacy: nothing is uploaded
The pattern is tokenised as plain text in the browser. It is not sent, not compiled against your data, and not stored between visits.
Frequently asked questions
Does it validate my regex?
No. It explains the tokens; syntax errors are only visible when a real engine tries to compile the pattern.
Why is the scope of a quantifier not shown?
Token-by-token scanning avoids building a tree, so nesting is explained in prose instead of a diagram.
Which flavour does it assume?
Common JavaScript/PCRE semantics. Anything engine-specific needs checking in that engine before you rely on it.