FormatterHQ

Regex Explainer

Paste a regular expression and read what each part does in plain English, from character classes and quantifiers to lookarounds and named groups.

Input TEXT
Output TEXT
Ready.

How to use the Regex Explainer

  1. Paste the regular expression into the input, either bare (\d{3}-\d{4}) or as a literal with flags (/abc/gi).
  2. The explanation updates automatically: one line per token, indented to show nesting.
  3. Read the Flags section at the bottom for what each flag changes.
  4. Check the status line for the token count, the number of capturing groups and any JavaScript compatibility warning.

What the regex explainer does

Regular expressions are dense: ^(?:\+?1[-. ]?)?\(?\d{3}\)? packs a dozen decisions into a few characters. This regex explainer parses the pattern and writes one plain-English line per token, indented so you can see which parts sit inside which group. It is useful when you inherit a pattern from old code, review a pull request or want to confirm that a pattern from Stack Overflow does what its author claimed.

Example explanation

Input:

/^(?<year>\d{4})-(0[1-9]|1[0-2])$/

Output:

^         Assert the start of the string (or of a line with the m flag)
(?<year>  Start of capturing group #1 named "year"
  \d{4}   Match a digit (0-9), exactly 4 times
)         End of capturing group #1 named "year"
-         Match the character "-"
(         Start of capturing group #2
  0       Match the character "0"
  [1-9]   Match one character from the set: "1" to "9"
  |       OR — alternatively match the expression on the right
  1       Match the character "1"
  [0-2]   Match one character from the set: "0" to "2"
)         End of capturing group #2
$         Assert the end of the string (or of a line with the m flag)

The status line adds a summary — here "13 tokens, 2 capturing groups". Group numbers follow the same left-to-right order JavaScript uses, so you know which one is $1 or match[2].

What the explainer understands

  • Groups: capturing, named ((?<name>…) and the Python-style (?P<name>…)), non-capturing (?:…), positive and negative lookahead and lookbehind, and PCRE atomic groups (?>…).
  • Quantifiers: *, +, ? and {n,m}, each labeled greedy, lazy (*?) or possessive (*+). A quantifier after ) is described as repeating the whole group.
  • Character classes: sets and ranges such as [a-f0-9], negated sets [^…], POSIX classes like [:alpha:] and escapes inside classes.
  • Escapes: \d, \w, \s, \b, hex and Unicode escapes (\x41, é, \u{1F600}), Unicode properties (\p{L}), back-references (\1, \k<name>) and control characters.
  • PCRE extras: \A, \Z, \z, \G, \h, \R and inline modifiers such as (?i), each marked "(PCRE)".
  • Flags: anything after the closing slash (g, i, m, s, u, y, d, v, and x for PCRE) is listed with a short description.

JavaScript vs PCRE patterns

The explainer reads patterns written for PHP, Python or Java as well as JavaScript. After explaining the pattern it also tries to compile it with the browser's RegExp. If that fails, the status line adds "not valid JavaScript syntax (PCRE-only features?)". For example, \Aabc(?i)x++ is explained token by token, but JavaScript would reject it because it has no \A, no inline modifiers and no possessive quantifiers.

Common errors the explainer reports

  • Missing ")" — 1 group(s) not closed. Count your parentheses; an escaped \( does not open a group.
  • Quantifier "+" at position 0 has nothing to repeat. A quantifier must follow a character, class or group. Escape it as \+ if you meant a literal plus.
  • Unterminated character class. A [ without a matching ], often caused by a literal bracket that should be \[.
  • Anchor cannot be quantified. Patterns like ^* are almost always a typo.

Once you understand the pattern, try it on real text in the regex tester, or generate matching sample strings with the random data from regex tool to see what it accepts.

Privacy

Parsing happens entirely in your browser. The pattern you paste is never sent to a server, so internal validation rules and proprietary patterns stay on your machine.

Frequently asked questions

Can it explain regex from PHP, Python or Java?
Yes. It recognizes common PCRE syntax such as possessive quantifiers, atomic groups, \A and \Z anchors, inline modifiers and Python-style (?P<name>…) groups. It then warns you if the pattern would not compile as a JavaScript RegExp.
Do I need to include the slashes and flags?
No. You can paste a bare pattern or a full literal like /^\w+$/im. When slashes are present, the flags after the closing slash are explained in a separate Flags section.
What is the difference between greedy, lazy and possessive quantifiers?
A greedy quantifier (+) matches as much as possible and gives characters back if the rest of the pattern fails. A lazy one (+?) matches as little as possible. A possessive one (++) never gives characters back; it exists in PCRE and Java but not in JavaScript.
How are capturing groups numbered?
Groups are numbered by the position of their opening parenthesis, from left to right, and named groups get a number too. Non-capturing groups and lookarounds are not counted. The explainer shows the number next to each group so you can map it to $1, $2 and so on.
Does the explainer test the regex against text?
No, it only describes the pattern. To see which strings it matches, paste the same pattern into the regex tester along with some sample text.

Last updated October 3, 2026

Guides

Related tools

Random Data from Regex Generate random strings that match a regular expression — ideal for test data such as IDs, codes and formats. Regex Cheat Sheet Interactive regex cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and Unicode, with clickable examples and a flavour table. Regex Escape Escape special characters so any text can be matched literally inside a regular expression in JavaScript, PCRE, Python or Java. Regex Patterns Library Copy-ready regex patterns for email, phone, URL, IP, dates, numbers, UUIDs, postal codes and passwords, each with examples and a live test box. Regex Tester Test JavaScript regular expressions live: highlight matches, inspect capture groups and named groups, try flags and preview replacements. SemVer Checker & Range Tester Validate, compare and sort semantic versions and test them against npm-style ranges like ^1.2.0, ~2.3 or >=1.0 <2. Snowflake ID Decoder Convert Twitter/X, Discord, Instagram and other Snowflake IDs to timestamps and show worker, process and sequence bits. Time Sheet Calculator Add up weekly work hours from start and end times with breaks. Calculates overtime per day or week and optional gross pay. TOTP / 2FA Code Generator Generate live TOTP 2FA codes from a Base32 secret or otpauth:// URI, create new secrets and QR codes for authenticator apps. ULID Decoder Decode ULIDs to their embedded timestamp and random part, and convert between ULID and UUID formats. Un-Google Link Remove Google redirect wrappers (google.com/url, AMP, image results) and tracking parameters to get the real destination URL. Unix Timestamp Converter Convert Unix epoch timestamps to human dates and dates to timestamps, in UTC, local time and any time zone.