Regex Tester
Test regular expressions with real-time match highlighting and capture groups.
Test String
What are Regular Expressions?
Regular expressions (regex) are patterns used to match and manipulate text. They're supported in virtually every programming language and text editor. A regex defines a search pattern using special characters — for example,
\d+ matches one or more digits, and [a-z]+@[a-z]+\.com matches simple email addresses. Regex is essential for input validation, text parsing, search-and-replace, and log analysis.Regex Syntax Quick Reference
- . — Matches any character (except newline)
- \d — Digit (0-9), \D — Non-digit
- \w — Word character (a-z, A-Z, 0-9, _), \W — Non-word
- \s — Whitespace, \S — Non-whitespace
- ^ — Start of string, $ — End of string
- * — Zero or more, + — One or more, ? — Zero or one
- {n,m} — Between n and m occurrences
- [abc] — Character class, [^abc] — Negated class
- (group) — Capturing group, (?:group) — Non-capturing group
- a|b — Alternation (a or b)
Common Regex Patterns
Here are some of the most frequently used regex patterns for common validation and extraction tasks.
// Email (simplified)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
// URL
https?:\/\/[^\s/$.?#].[^\s]*
// IPv4 Address
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
// Date (YYYY-MM-DD)
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
// Phone (US)
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
// Strong Password (8+ chars, upper, lower, digit, special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Regex Flags Explained
- g (Global): Find all matches, not just the first
- i (Case-insensitive): Match regardless of letter case
- m (Multiline): ^ and $ match line boundaries, not just string start/end
- s (Dotall): Makes . match newline characters too
- u (Unicode): Enables full Unicode matching
- y (Sticky): Matches only from the lastIndex position
Frequently Asked Questions
- What's the difference between * and + in regex?
- * matches zero or more occurrences (the preceding element is optional), while + requires one or more occurrences. For example, ab*c matches 'ac', 'abc', and 'abbc', but ab+c only matches 'abc' and 'abbc' — not 'ac'.
- How do I match a literal dot or other special character?
- Escape it with a backslash: \. matches a literal dot. Other characters that need escaping include: ^ $ . * + ? ( ) [ ] { } | \. Inside a character class [...], most special characters lose their meaning except ] \ ^ and -.
- What are capture groups and when should I use them?
- Capture groups, defined with parentheses (), extract matched substrings. Use them when you need to: extract parts of a match (e.g., area code from a phone number), backreference within the pattern (\1), or apply quantifiers to a group. Use (?:...) for grouping without capturing.
- Why is my regex slow or causing a timeout?
- Catastrophic backtracking occurs with nested quantifiers like (a+)+ or (a|b)*c on non-matching input. The regex engine tries exponentially many paths. Fix by using atomic groups, possessive quantifiers, or restructuring the pattern. Avoid patterns like .*.*.
Guides
Related Tools
Hash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes from text.
JSON Formatter & ValidatorFormat, validate, and minify JSON with syntax highlighting.
Text Diff CheckerCompare two blocks of text and see the differences highlighted.
Mock Data GeneratorGenerate realistic fake data for testing. Customizable fields, JSON or CSV output.