What does the Regex Explainer do?
The Regex Explainer deconstructs complex regular expressions into step-by-step, plain English token breakdowns in real time. It parses regex patterns into constituent components—anchors (^, $), quantifiers (+, *, {2,4}), character classes (\d, [a-z]), lookarounds, alternation operators (|), and flags (g, i, m, s, u)—explaining what each token matches in plain language.
Core Concepts
- Token-by-Token Parsing: Deconstructs pattern strings into distinct structural nodes (e.g. anchors, escaped classes, greedy vs. lazy quantifiers, capture groups).
- Plain English Descriptions: Translates cryptic regex syntax into clear human explanations for code reviews and documentation.
- Flag Modifiers: Explains how active regex flags alter engine behavior (e.g. global matching
g, case insensitivityi, multiline modem, dotAll modes, unicodeu).
How to use the tool?
- Enter Regex Pattern: Paste your regex pattern into the input box or pick a preset (Email, IPv4, IPv6, UUID, URL, ISO Date, JWT, API Key, SemVer, Hex Color).
- Configure Flags: Toggle active flags (
g,i,m,s,u) in the top bar. - Instant Token Breakdown: The plain English explanation table and active flags summary update immediately as you type.
- Copy & Download: Click Copy to export the structured explanation to your clipboard or Download to save it as a text report.
Related Developer Utilities
If you work with pattern matching, string validation, and data formatting, explore these complementary tools:
- Regex Tester & Validator: Test regular expressions in real time against custom test strings.
- JSON Formatter & Beautifier: Format and prettify extracted JSON data payloads.
- Base64 Decoder & Encoder: Encode or decode base64 strings and binary payloads.
- Text Case Converter: Convert raw text strings across UPPERCASE, camelCase, and snake_case.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/regex/explainer) to programmatically deconstruct and explain regular expression patterns.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
pattern |
String / Object | Regular expression pattern string or payload object (aliases: regex, rawText, expression). |
"^[0-9]{3}$" |
flags |
String | Optional regex flags ("g", "i", "m", "s", "u"). Defaults to "g". |
"g" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/regex/explainer \
-H "Content-Type: application/json" \
-d '{
"pattern": "^[0-9]{3}$",
"flags": "g"
}'Python
import requests
url = "https://blueutils.com/api/regex/explainer"
payload = {
"pattern": "^[0-9]{3}$",
"flags": "g"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"pattern": "^[0-9]{3}$",
"flags": "g"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/regex/explainer"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Returns true if pattern compiled and deconstructed successfully. |
true |
pattern |
String | Echoes the input regex pattern string. | "^[0-9]{3}$" |
flags |
String | Active flag modifiers used. | "g" |
tokenCount |
Number | Total count of individual regex tokens analyzed. | 4 |
breakdown |
Array | Array of token objects containing token, type, and description. |
[...] |
flagDescriptions |
Array | Human-readable descriptions for active flags. | ["Global (g): ..."] |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"pattern": "^[0-9]{3}$",
"flags": "g",
"tokenCount": 4,
"breakdown": [
{
"token": "^",
"type": "Anchor",
"description": "Asserts the start of the string line"
},
{
"token": "[0-9]",
"type": "Character Set",
"description": "Matches ANY single character listed in '0-9'"
},
{
"token": "{3}",
"type": "Quantifier Range",
"description": "Matches exactly 3 times of the preceding token"
},
{
"token": "$",
"type": "Anchor",
"description": "Asserts the end of the string line"
}
],
"flagDescriptions": [
"Global (g): Finds all matching occurrences rather than stopping after first match"
]
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid Regular Expression syntax: Unterminated character class"
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to explain regular expressions?
Integrating the Regex Explainer API into code review bots, automated documentation generators, or AI agent tool chains provides key benefits:
- Rapid Script Validation: Automatically documents and annotates regex patterns inside codebase repositories during CI linting.
- Optimized Token Efficiency for AI Agents: LLMs often hallucinate regex explanations when parsing complex lookarounds. Invoking the API returns a structured, deterministic token AST breakdown without token burn.
- Deterministic Accuracy Without Hallucinations: Ensures 100% accurate token-level deconstruction according to ECMAScript standard regular expression specifications.
Native Usage
How to deconstruct or inspect regular expressions locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Compile and test regex pattern in PowerShell
python -c "import re; p = re.compile(r'^[0-9]{3}$'); print('Valid regex pattern with flags:', p.flags)"Linux / Unix (Bash)
# Test regex validity using Node.js
node -e "try { new RegExp('^[0-9]{3}$', 'g'); console.log('Pattern is valid'); } catch(e) { console.error(e.message); }"Python
Using Python re.Scanner or regex debugging in Python:
import re
pattern = r"^[0-9]{3}$"
try:
compiled = re.compile(pattern)
print(f"Pattern '{pattern}' compiled successfully.")
except re.error as err:
print(f"Regex error: {err}")Java
Using Java java.util.regex.Pattern:
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class RegexExplainerExample {
public static void main(String[] args) {
String regex = "^[0-9]{3}$";
try {
Pattern pattern = Pattern.compile(regex);
System.out.println("Pattern compiled successfully: " + pattern.pattern());
} catch (PatternSyntaxException e) {
System.err.println("Regex syntax error: " + e.getMessage());
}
}
}