Explain a regex pattern in plain language
See what each piece of a regular expression does: the sample email pattern splits into 16 explained parts with 3 capture groups, the first named user, each with its position and a plain description. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Flags
- i
- Flavor
- ECMAScript
- Capturing groups
- 3
A regular expression can be compact enough to fit on one line while hiding several independent rules. This explainer validates an ECMAScript pattern, scans it from left to right, and labels its groups, quantifiers, character classes, anchors, escapes, alternatives, wildcards, and literal text. Each component includes its source position, nesting depth, and a plain-language description, making the result useful for review, learning, documentation, and debugging without changing or executing the pattern against private data.
Read the explanation in pattern order
Start with the components array, which follows the exact left-to-right order of the source pattern. Every entry identifies a type, preserves the original token, and reports a zero-based index and token length. Those positions let you connect an explanation to the precise characters in a long expression instead of guessing which parenthesis or question mark it describes.
The depth value shows where a token sits inside nested groups. Group-start and group-end entries make the structure explicit, while capturing groups receive their capture number in opening order. Named captures also retain their name.
Literal runs are kept together when possible, so ordinary text remains readable rather than becoming one noisy record per character. Read the entries sequentially first, then use the counts to locate the constructs that deserve closer review, such as several nested groups or numerous alternatives.
Understand groups, classes, and repetition
Groups define structure and sometimes capture text for later use. A plain parenthesis starts a numbered capture, a question-mark colon starts a non-capturing group, and named captures are reported with their declared name. Lookahead and lookbehind assertions are distinguished because they test surrounding text without consuming it.
Character classes are explained as matching one listed character, with negated classes called out and simple ranges such as A through Z summarized. Escapes receive descriptions for common categories including digits, word characters, whitespace, boundaries, backreferences, Unicode properties, and encoded characters. Quantifiers are attached conceptually to the item immediately before them: an asterisk means zero or more, a plus means one or more, a question mark means optional, and brace forms state exact, minimum, or bounded repetition.
A trailing question mark changes a repetition from greedy to lazy, so the explanation explicitly notes that it prefers fewer repetitions. These descriptions expose the building blocks without pretending to predict every possible match.
Validate syntax and recognize the flavor
The pattern is validated with the ECMAScript regular expression engine before any explanation is returned. This matters because regular-expression dialects differ: syntax copied from PCRE, Python, Java, or . NET may not mean the same thing in JavaScript, and some constructs may be rejected entirely.
Supply the expression body without slash delimiters and place optional JavaScript flags in the flags field. Validation establishes that the expression can compile; it does not prove that the expression matches the business data you intended, performs efficiently on every input, or is safe from excessive backtracking. Use the explanation to review structure, then test representative matching and non-matching samples with a regex tester.
What you can do with it
Review an inherited expression
Turn a dense pattern from an old codebase into an ordered list of understandable constructs before modifying it.
Document validation rules
Generate structured notes for groups, allowed characters, anchors, and repetition rules used by a form or service.
Learn regular expression syntax
Compare the original tokens with concise explanations and source positions while studying ECMAScript patterns.
FAQ
Which regular expression flavor does this explain?
It validates and explains ECMAScript regular expressions, the syntax used by JavaScript RegExp.
Should I include surrounding slash characters?
No. Send only the pattern body in pattern, and put any flags such as i or m in the separate flags field.
Does this tool test the pattern against my text?
No. It explains syntax only and does not need subject text. Use a regex tester separately to verify intended matches.
Can it identify named and numbered capture groups?
Yes. Capturing groups are numbered by opening order, and named groups also include their declared name.
What does a question mark after a repeat mean?
It makes the repetition lazy, so it prefers fewer repetitions, and the explanation says so explicitly. On its own right after an item, a question mark simply makes that item optional.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/dev2/regex-explain \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"pattern":"^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,})$"}'const res = await fetch("https://api.kit.forhosting.com/dev2/regex-explain", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"pattern": "^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,})$"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev2/regex-explain",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"pattern": "^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,})$"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev2/regex-explain", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"pattern":"^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\\\.([A-Za-z]{2,})$"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"pattern":"^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,})$"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev2/regex-explain", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"pattern": "^(?<user>[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,})$"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev2.regex_explain",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_pattern_chars | 2000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Read the explanation in pattern order
The summary gives a quick count, and component_counts is convenient for automated documentation or lint-style reports.
Validate syntax and recognize the flavor
Invalid syntax, unsupported flags, and duplicate flags return a typed invalid_input error rather than a partial or misleading explanation. Because the algorithm is deterministic, uses no network, and does not inspect subject text, the same pattern and flags always produce the same structured explanation in the browser and through the API.
Technical questions
What happens when the regex is invalid?
The request returns an invalid_input error containing the compilation problem. It does not return a partial explanation.
What does an API request cost?
The API base price is $0.002 per request. The same deterministic logic can also run in the browser.