What does the Regex Tester & Validator do?
The Regex Tester & Validator compiles, validates, and tests regular expression (regex) patterns against arbitrary text in real time. It calculates full match indices, extracts numbered and named capture groups, supports standard flags (g, i, m, s), and performs ReDoS safety vulnerability checks.
Core Concepts
- Global Matching (
g): Scans through the entire document to capture all matches rather than halting at the first match. - Case-Insensitive Matching (
i): Matches upper and lowercase characters identically without requiring explicit range duplication ([a-zA-Z]). - Multiline Anchors (
m): Changes^and$from matching document start/end to matching the beginning and end of each individual line. - DotAll Matching (
s): Allows the.wildcard to match newline characters (\n,\r). - Capture Groups & Named Groups: Parentheses
(...)capture sub-patterns into numbered indices, while(?<name>...)extracts named dictionary properties.
How to use the tool?
- Enter Pattern or Select Preset: Type your regex pattern into the expression input or select a preset from the master toolbar (Email, IPv4, UUID, URL, ISO Date, JWT, API Key).
- Toggle Flags & Input Text: Set active flags (
g,i,m,s) and type or paste your target test string. - Instant Real-Time Inspection: Extracted matches, offset character indices, capture groups, and ReDoS safety warnings update instantly on every keystroke.
- Export & Download: Click Copy to copy the complete match report to your clipboard or Download to save it as a text file.
Related Developer Utilities
If you are working with text processing, pattern matching, and data validation, explore these related tools:
- Regex Explainer: Deconstruct complex regex syntax into plain English token breakdowns.
- JSON Syntax Validator: Validate JSON syntax and inspect line/column errors.
- Text Diff Tool: Compare two text documents side-by-side to highlight additions and deletions.
- Base64 Encoder & Decoder: Encode and decode standard and URL-safe Base64 strings.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/regex/tester) to programmatically test, validate, and extract capture groups using JavaScript-compatible regular expressions.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
pattern |
String / Object | Regular expression pattern string or payload object (aliases: regex, rawText, expression). |
"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}" |
text |
String | Target text string to evaluate against the regex pattern (aliases: input, target, string). |
"Contact support@blueutils.com for help." |
flags |
String | Flag modifiers ("g", "i", "m", "s"). Defaults to "g". |
"g" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/regex/tester \
-H "Content-Type: application/json" \
-d '{
"pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"text": "Contact support@blueutils.com or dev@blueutils.com for help.",
"flags": "g"
}'Python
import requests
url = "https://blueutils.com/api/regex/tester"
payload = {
"pattern": r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b",
"text": "Server IP is 10.0.0.1 and Gateway is 10.0.0.254",
"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": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}",
"text": "Contact support@blueutils.com for help.",
"flags": "g"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/regex/tester"))
.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 the regex compiled and executed successfully. |
true |
pattern |
String | Echoes the validated regex pattern. | "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}" |
flags |
String | Active flag modifiers used. | "g" |
matchCount |
Number | Total count of pattern matches identified in text. | 2 |
isMatch |
Boolean | Returns true if at least one match was found. |
true |
matches |
Array | Array of match objects detailing match string, index position, and captured groups. | [...] |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"flags": "g",
"matchCount": 2,
"isMatch": true,
"matches": [
{
"match": "support@blueutils.com",
"index": 8,
"groups": []
},
{
"match": "dev@blueutils.com",
"index": 33,
"groups": []
}
]
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Regex Compilation Error: Invalid regular expression: /[a-z/: 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 test regular expressions?
Integrating the Regex Tester API into automated test suites, input validation services, or CI/CD pipelines provides several advantages:
- Rapid Script Validation: Enables developers to dynamically test user-submitted regex filters against sample datasets without deploying backend changes.
- Optimized Token Efficiency for AI Agents: LLMs often hallucinate regex match indices or fail complex lookarounds. Invoking the API provides exact match offsets and capture groups with zero reasoning token overhead.
- Deterministic Accuracy Without Hallucinations: Ensures 100% deterministic pattern execution adhering strictly to ECMAScript RegExp specifications.
Native Usage
How to test regular expressions locally using command-line utilities and scripts:
Windows (CMD / PowerShell)
# Match regular expression patterns in PowerShell
Select-String -Path .\logfile.txt -Pattern "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"Linux / Unix (Bash)
# Using grep with extended regular expressions (ERE)
grep -E -o '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' server.logPython
Using Python standard library re:
import re
pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
text = "Contact support@blueutils.com or dev@blueutils.com for help."
matches = re.finditer(pattern, text)
for m in matches:
print(f"Match: '{m.group()}' at index {m.start()}-{m.end()}")Java
Using java.util.regex.Pattern and Matcher:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTesterExample {
public static void main(String[] args) {
String regex = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}";
String text = "Contact support@blueutils.com or dev@blueutils.com for help.";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println("Found match: " + matcher.group() + " at index " + matcher.start());
}
}
}