Developer Utility
Regex Generator, Tester & Explainer
Build, test, and debug regular expressions in real-time with visual match highlighting, capture group extraction, substitution previews, and multi-language code snippets.
Common Production Presets:
TEST STRING
VISUAL MATCH HIGHLIGHT
SUBSTITUTION / REPLACE
MATCH DETAILS & GROUPS
PATTERN EXPLAINER
^ Start of string / line anchor.
$ End of string / line anchor.
+ Plus quantifier: Matches 1 or more occurrences of the preceding token.
{2,} Matches at least 2 occurrences.
// TypeScript / JavaScript
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const text = "Your text here";
// Test match
const isMatch = regex.test(text);
// Extract all matches
const matches = [...text.matchAll(regex)];
for (const match of matches) {
console.log("Match:", match[0], "Index:", match.index);
} Regular Expressions in Production: Best Practices
Regular expressions are essential for input validation, log parsing, tokenization, and text search. However, unoptimized regex in production can introduce severe performance bugs and security vulnerabilities.
1. Beware of Catastrophic Backtracking (ReDoS)
Patterns containing nested quantifiers like (a+)+$ or overlapping alternatives like (a|a)+$
have exponential time complexity $O(2^n)$. When evaluated against malicious non-matching inputs, they freeze the Node.js event loop
or exhaust server CPU threads (Regular Expression Denial of Service).
- Always avoid nesting quantifiers (e.g.
(x+)*). - Use atomic groups or possessive quantifiers where supported.
- Enforce strict string length limits before passing user inputs to regex engines.
2. Regex Flags Cheatsheet
| Flag | Name | Behavior |
|---|---|---|
g | Global | Finds all matches in the text rather than halting after the first occurrence. |
i | Ignore Case | Performs case-insensitive matching across uppercase and lowercase letters. |
m | Multiline | Treats ^ and $ as beginning and end of each individual line (separated by \n). |
s | DotAll | Allows the wildcard dot . to match newline characters as well. |
u | Unicode | Enables full Unicode character class escaping and handling of 32-bit surrogate pairs. |