Regular Expressions (Regex) are one of the most powerful—and intimidating—tools in a developer's arsenal. A single line of regex can replace 50 lines of complex string parsing logic. It allows you to validate emails, extract dates, parse logs, and sanitize inputs with surgical precision.
However, regex syntax is dense and unforgiving. A missing backslash or unescaped dot can break everything. The Regex Tester is your sandbox. It allows you to build, test, and debug patterns against real text strings in real-time, giving you immediate visual feedback on what matches and what doesn't.
How the Tester Works
Type your regex pattern in the top box and your test string in the bottom box. The tool instantly highlights matches in blue. Hover over a match to see capturing groups $1, $2, etc.
Regex Cheat Sheet (Quick Reference)
Character Classes
.: Any character except newline.\d: Digit (0-9).\w: Word character (a-z, A-Z, 0-9, _).\s: Whitespace (space, tab, newline).[abc]: Any character in the set.[^abc]: Any character NOT in the set.
Quantifiers
*: 0 or more times.+: 1 or more times.?: 0 or 1 time (Optional).{3}: Exactly 3 times.{3,6}: Between 3 and 6 times.
Anchors
^: Start of string/line.$: End of string/line.: Word boundary.
Advanced Features
Groups and Capturing
Use parentheses (...) to group parts of your pattern. This isolates sub-matches using standard indexing ($1, $2).
Example: (\d{4})-(\d{2}) extracts Year and Month separately.
Flags
- g (Global): Find all matches, not just the first one.
- i (Insensitive): Case-insensitive match.
- m (Multiline):
^and$match start/end of line, not just string.
Lookahead & Lookbehind
These allow you to match a pattern only if it is (or isn't) followed/preceded by another pattern.
(?=foo): Positive Lookahead (Match only if followed by "foo").(?!foo): Negative Lookahead (Match only if NOT followed by "foo").
Common Real-World Patterns
1. Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
2. Strong Password
At least 8 chars, one uppercase, one number, one special char.
^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
3. Slugify
Match non-alphanumeric chars to replace them.
/[^a-z0-9]+/gi
Performance Warning: Catastrophic Backtracking
Be careful with nested quantifiers like (a+)+. If run against a non-matching string, the engine might try exponentially many combinations, freezing your server (ReDoS attack). Always test your regex against long, non-matching strings to ensure performance safety.