Regex Tester Complete Guide
Master regular expressions with real-time testing, ReDoS detection, and code generation. Learn regex patterns and avoid common security pitfalls.
What is a Regular Expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It's used for pattern matching, validation, and text manipulation in programming.
Example: Email validation pattern matching [email protected] format
Essential Regex Patterns
| Pattern | Meaning | Example |
|---|---|---|
| \d | Any digit (0-9) | Matches: 5, 9, 0 |
| \w | Word character (a-z, A-Z, 0-9, _) | Matches: a, Z, _ |
| \s | Whitespace | Matches: space, tab |
| . | Any character (except newline) | Matches: a, 1, @ |
| ^ | Start of string/line | ^Hello matches "Hello world" |
| $ | End of string/line | world$ matches "Hello world" |
| [abc] | Character set | Matches: a, b, or c |
Quantifiers
*Zero or more
a* matches "", "a", "aaa"
+One or more
a+ matches "a", "aaa"
?Zero or one (optional)
colou?r matches "color", "colour"
{n}Exactly n times
\d{3} matches "123"
{n,}n or more times
\d{2,} matches "12", "123456"
{n,m}Between n and m times
\d{2,4} matches "12", "1234"
Regex Flags Explained
Global
Find all matches instead of stopping at the first match
Case Insensitive
Match both uppercase and lowercase letters
Multiline
^ and $ match start/end of each line, not just string
Dotall (Single line)
. matches newline characters too
ReDoS Vulnerability Prevention
ReDoS (Regular Expression Denial of Service) occurs when a regex pattern causes catastrophic backtracking, freezing your application.
Dangerous Patterns to Avoid:
(a+)+Nested quantifiers(a|aa)+Overlapping alternatives(.*a){10}Greedy quantifiers in groupsSafe Alternatives:
a+Simple quantifier (no nesting)[^a]*aNegated character classTry Our Regex Tester
Test your patterns with real-time matching, ReDoS detection, and code generation for 6+ languages.
Open Regex TesterQuick Reference Cheat Sheet
Character Classes
\d = [0-9]
\w = [A-Za-z0-9_]
\s = whitespace
\D, \W, \S = negated
Lookaround
(?=...) = lookahead
(?!...) = negative lookahead
(?<=...) = lookbehind
(?<!...) = negative lookbehind