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.

Free Tool

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. 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. 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. 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. 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

TokenMeaningExample
^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 newlinec.t matches "cat", "cut", "c1t"
\dAny digit (0-9)\d{3} matches "123"
\DAny non-digit character\D+ matches "abc"
\wAny word character (a-z, A-Z, 0-9, underscore)\w+ matches "hello_42"
\WAny non-word character\W matches " " or "!"
\sAny whitespace (space, tab, newline)hello\sworld matches "hello world"
\SAny non-whitespace character\S+ matches "hello"
*Zero or more of the preceding elementab* matches "a", "ab", "abbb"
+One or more of the preceding elementab+ 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 repetitionsa{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 casePatternExplanation
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

Frequently asked questions

What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used in programming to find, match, or replace text based on rules rather than exact strings. Regex is supported in almost every programming language including JavaScript, Python, Java, and PHP.
What does the dot mean in regex?
In regex, a dot matches any single character except a newline by default. For example, the pattern c.t matches cat, cut, cot, and c4t. To match a literal dot, you must escape it with a backslash like this: \. This is one of the most common sources of regex mistakes.
What is the difference between plus and asterisk in regex?
The plus sign means one or more occurrences of the preceding element. The asterisk means zero or more occurrences. So \d+ matches one or more digits (requiring at least one digit) while \d* matches zero or more digits (matching even an empty string). Use plus when the element must be present at least once.
What are capturing groups in regex?
Capturing groups are portions of a regex enclosed in parentheses that capture the matched text for later use. For example in (\d{4})-(\d{2})-(\d{2}) the three groups capture year, month, and day separately. Non-capturing groups use (?:) syntax and group without saving the match.
What is the difference between greedy and lazy matching?
Greedy quantifiers (the default) match as much text as possible. Lazy quantifiers (add ? after the quantifier like +? or *?) match as little as possible. For example on the string hello world, .+ matches the entire string while .+? matches just h. Use lazy matching when you want the shortest possible match.
What does the caret mean inside and outside brackets?
Outside a character class, caret (^) anchors the match to the start of the string. Inside a character class like [^abc], it negates the class and means any character except those listed. These are two completely different uses of the same character, which is a common source of confusion for regex beginners.
How do I match a literal special character in regex?
Escape it with a backslash. Special characters that need escaping are: . * + ? ^ $ { } [ ] | ( ) and /. For example to match a literal dot use \. and to match a literal parenthesis use \( and \). In JavaScript string literals you may need to double the backslash like \\.
What regex flags are available in JavaScript?
JavaScript supports six regex flags: g (global, find all matches), i (case insensitive), m (multiline, makes ^ and $ match line boundaries), s (dotall, makes dot match newlines), u (unicode mode), and d (generate indices for substring matches). Flags are added after the closing slash like /pattern/gi.

Related guides

Related tools