Regex Tester
Test your regular expressions in real-time.
//
Match Results (0)
No matches found.
Common Patterns (Cheat Sheet)
[abc]A single character of: a, b or c[^abc]Any single character except: a, b, or c[a-z]Any single character in the range a-z.Any single character (except newline)\sAny whitespace character\dAny digit (0-9)\wAny word character (a-zA-Z0-9_)
Quantifiers & Flags
a?Zero or one of aa*Zero or more of aa+One or more of aa{3}Exactly 3 of a- g Global: Don't return after first match
- i Insensitive: Case insensitive match
- m Multiline: ^ and $ match start/end of line
About This Tool
A Regular Expression (Regex) is a sequence of characters that specifies a precise search pattern. Developers use regex extensively to validate form inputs, find and replace strings within large documents, or extract crucial pieces of data from logs and HTML.
When to Use
- Validating user input formatting (e.g., checking if a string is a valid email, phone number, or IP address).
- Scraping websites or parsing raw server logs.
- Refactoring massive codebases using complex 'Find and Replace' logic.
Practical Examples
Email Validation^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Extracting Digits only\d+
Finding Hex Colors^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Common Mistakes to Avoid
- Forgetting to escape special reserved characters (like ., *, ?, +, [, (, etc.) when you literally want to match them.
- Writing 'greedy' quantifiers (* or +) that match way more text than intended. Use *? or +? to make them 'lazy'.
Frequently Asked Questions
Q. What do the flags /g, /i, and /m do?A. 'g' means global search (find all occurrences instead of stopping after the first). 'i' makes the match case-insensitive. 'm' treats the string as multiple lines so ^ and $ match the start/end of each line.
Q. Why is Regex so hard to read?A. Regex is extremely dense. Always test your patterns before putting them into production code to catch catastrophic backtracking bugs.