Regex Explainer
Paste any regular expression and get a plain English token-by-token breakdown. Test matches, see captured groups, and learn from 8 built-in examples.
Quick Answer
How do I read a regular expression?
Read a regex left to right, token by token. Anchors like ^ and $ mark position. Character classes like \d (digit) and \w (word character) match types of characters. Quantifiers like + (one or more) and * (zero or more) control repetition. Groups in parentheses capture matches. This tool breaks any regex into a plain English token table automatically.
Regex Pattern
Test String
About this tool
This regex explainer parses any regular expression and breaks it into individual tokens, each labeled by type (anchor, character class, quantifier, group, character set, or literal) and explained in plain English. It also generates a one-sentence summary of what the whole pattern does. You can test your pattern against any string to see matches highlighted in real time, with captured groups extracted and listed separately.
Regex is one of the most powerful and frequently misread tools in programming. A pattern like ^(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$ looks cryptic at a glance but has a precise meaning in each token. This tool is useful for developers learning regex, debugging an existing pattern, reviewing a pattern written by someone else, or preparing a regex for documentation. The 8 built-in examples cover the most common real-world use cases from email validation to HTML tag matching.
How it works
- 1
Tokenization
The parser scans the pattern left to right, identifying each token: escape sequences like \d, anchors like ^ and $, groups bounded by parentheses (including non-capturing (?:) and lookahead (?=) variants), character sets in brackets, quantifiers (* + ? {}), and literal characters.
- 2
Classification
Each token is assigned a type and color: anchors (blue), character classes (purple), quantifiers (amber), groups (emerald), character sets (indigo), escaped characters (orange), alternation (pink), and literals (gray). This makes it easy to identify what each part does at a glance.
- 3
Summary generation
A one-sentence summary is generated from the token list, noting whether the pattern is anchored to the start and end of the string, how many capturing groups it contains, and whether it uses lookahead assertions.
- 4
Live match testing
The test string section applies the regex using the JavaScript RegExp engine. Matches are highlighted inline. All captured groups from every match are extracted and displayed with match index and group number.
Common regex tokens reference
| Token | Meaning | Example |
|---|---|---|
^ | Start of string (or line with m flag) | ^Hello matches "Hello world" |
$ | End of string (or line with m flag) | world$ matches "Hello world" |
. | Any character except newline | c.t matches "cat", "cut", "c1t" |
\d | Any digit (0-9) | \d{3} matches "123" |
\D | Any non-digit character | \D+ matches "abc" |
\w | Any word character (a-z, A-Z, 0-9, underscore) | \w+ matches "hello_42" |
\W | Any non-word character | \W matches " " or "!" |
\s | Any whitespace (space, tab, newline) | hello\sworld matches "hello world" |
\S | Any non-whitespace character | \S+ matches "hello" |
* | Zero or more of the preceding element | ab* matches "a", "ab", "abbb" |
+ | One or more of the preceding element | ab+ matches "ab", "abbb" (not "a") |
? | Zero or one of the preceding element (optional) | colou?r matches "color" and "colour" |
{n,m} | Between n and m repetitions | a{2,4} matches "aa", "aaa", "aaaa" |
[abc] | Any one character from the set | [aeiou] matches any vowel |
(abc) | Capturing group -- saves the matched text | (\d+) captures the digit(s) |
Common regex patterns
| Use case | Pattern | Explanation |
|---|---|---|
| Email address | ^[\w.-]+@[\w.-]+\.\w{2,}$ | Validates a basic email format with domain and TLD |
| URL (http/https) | https?:\/\/[\w.-]+(\/\S*)? | Matches http or https URLs with optional path |
| Phone (US) | ^\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}$ | Matches (555) 555-5555 or 555-555-5555 formats |
| ZIP code | ^\d{5}(-\d{4})?$ | Matches 5-digit or ZIP+4 (e.g. 90210-1234) |
| IPv4 address | ^(\d{1,3}\.){3}\d{1,3}$ | Matches dotted-decimal notation like 192.168.1.1 |
| Hex color | ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ | Matches #fff or #ffffff format |
| Date YYYY-MM-DD | ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ | Validates ISO date with month and day ranges |
| Username | ^[a-zA-Z][a-zA-Z0-9_]{2,19}$ | 3-20 chars, starts with letter, allows underscore |