What does the Regex Generator & Pattern Matcher do?
The Regex Generator & Pattern Matcher allows developers to generate and validate regular expressions against their actual source text in real time. When you provide source text (such as application logs, JSON payloads, or raw documents) on blueutils.com, the tool synthesizes patterns from 50 built-in templates (including IPv4/IPv6 addresses, URLs, Email Addresses, UUIDs, ISO dates, and SemVer strings) or custom search terms and evaluates matching substrings immediately in-browser.
Additionally, the tool verifies regular expressions against ReDoS (Regular Expression Denial of Service) catastrophic backtracking vulnerabilities and provides plain-text match summaries with character offsets.
How to use the tool?
- Select Preset or Enter Terms: Choose from the 50 categorized presets, enter comma-separated search words, or specify regex sub-patterns.
- Input Source Text: Paste your target sample text or logs into the Target Source Text editor or click Load Sample.
- Configure Modifiers: Toggle modifier flags (
gfor global multi-match,ifor case-insensitive matching,mfor multiline mode). - Inspect Live Matches: View the generated regex literal, match count, character offset positions, ReDoS security rating, and plain-text extraction report.
- Download & Copy: Use the dedicated Copy Regex button, copy the match report to clipboard, or download the match report as a text file.
Related Developer Utilities
- Regex Tester & Validator: Test and highlight regular expressions with detailed capture groups.
- Regex Explainer: Deconstruct regular expressions into plain English token explanations.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/regex/regex-generator) for programmatic regex generation, recommendation, and source text matching.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
sourceText |
String | The target source text to analyze and match against. | "Order INV-10294 sent to dev@blueutils.com" |
targetPattern |
String | Regular expression pattern to compile and match (optional, auto-detected if omitted). | "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}" |
flags |
String | Regex flags (g, i, m). Defaults to "g". |
"g" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/regex/regex-generator \
-H "Content-Type: application/json" \
-d '{
"sourceText": "Order INV-10294 sent to dev@blueutils.com from IP 192.168.1.1",
"targetPattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"flags": "g"
}'Python
import requests
url = "https://blueutils.com/api/regex/regex-generator"
payload = {
"sourceText": "Order INV-10294 created for support@blueutils.com",
"targetPattern": "\\b[A-Z]{2,10}-\\d+\\b",
"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 = """
{
"sourceText": "Server 192.168.0.1 responded in 42ms",
"flags": "g"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/regex/regex-generator"))
.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 | Indicates whether generation and matching succeeded. | true |
message |
String | Human-readable result status summary. | "Regex generated successfully with 2 matches." |
result |
String | Standard regex literal output. | "/admin@example\\.com/g" |
pattern |
String | The compiled regular expression pattern. | "admin@example\\.com" |
flags |
String | Regular expression modifier flags. | "g" |
regexLiteral |
String | Formatted regex literal. | "/admin@example\\.com/g" |
isMatch |
Boolean | True if one or more matches exist in sourceText. | true |
matchCount |
Number | Total number of matches extracted. | 2 |
matches |
Array | List of extracted matches with start index positions and capture groups. | [{"match":"admin@example.com","index":142,"groups":[]}] |
textOutput |
String | Formatted plain-text match summary report. | "MATCH SUMMARY: 2 matches found..." |
redos |
Object | Safety evaluation (isSafe, riskLevel). |
{ "isSafe": true, "riskLevel": "low" } |
originalSize |
Number | Byte size of raw input payload in UTF-8. | 48 |
resultSize |
Number | Byte size of output payload in UTF-8. | 56 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "Regex generated successfully with 2 matches.",
"result": "/admin@example\\.com/g",
"pattern": "admin@example\\.com",
"flags": "g",
"regexLiteral": "/admin@example\\.com/g",
"isMatch": true,
"matchCount": 2,
"matches": [
{
"match": "admin@example.com",
"index": 142,
"groups": []
}
],
"textOutput": "========================================================\nMATCH SUMMARY: 2 matches found\nPATTERN: /admin@example\\.com/g\n========================================================\n\nEXTRACTED MATCHES:\n[#1] \"admin@example.com\" (at character offset 142)\n",
"redos": {
"isSafe": true,
"riskLevel": "low",
"warning": null
},
"originalSize": 48,
"resultSize": 56
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Please select a Preset in Input 2, enter Search Text(s) in Input 3, or enter Regex Pattern(s) in Input 4.",
"message": "Please select a Preset in Input 2, enter Search Text(s) in Input 3, or enter Regex Pattern(s) in Input 4."
}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 generate and match regular expressions?
Integrating the Regex Generator API into CI/CD pipelines, DevOps scripts, or automated agent workflows provides several practical advantages:
- Rapid Script Validation: Enables developers and infrastructure engineers to quickly test and programmatically verify calculations or configurations across multiple environments.
- Optimized Token Efficiency for AI Agents: Offloading parsing and deterministic calculations to an external API significantly cuts prompt and completion token consumption for autonomous agents.
- Deterministic Accuracy Without Hallucinations: Language models can occasionally miscalculate or hallucinate subtle edge cases. Delegating processing to a deterministic API guarantees 100% computational accuracy every time without token overhead.
Native Usage
How to achieve the same task locally without external dependencies using native operating system utilities and scripting languages:
Windows (CMD / PowerShell)
# PowerShell regex matching and group extraction
$text = 'Order INV-10294 sent to dev@blueutils.com'
$pattern = '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
if ($text -match $pattern) {
Write-Host "Matched email: $($Matches[0])"
}Linux / Unix (Bash / Shell)
# Bash grep PCRE extraction
TEXT="Order INV-10294 sent to dev@blueutils.com"
echo "$TEXT" | grep -o -P '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'Python
# Native Python standard library re module
import re
text = "Order INV-10294 sent to dev@blueutils.com"
pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
matches = re.findall(pattern, text)
print(f"Extracted matches: {matches}")Java
// Native Java standard library Pattern matching
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RegexExtractor {
public static void main(String[] args) {
String text = "Order INV-10294 sent to dev@blueutils.com";
Pattern pattern = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println("Match: " + matcher.group());
}
}
}