🧩Regex Tester
Test and validate your regular expressions instantly. Enter a pattern, add flags, and test against your string to see live matches.
Frequently Asked Questions
🤔 What is a regex?
A regular expression (regex) is a sequence of characters that define a search pattern, often used for string matching and validation.
🔍 How does this regex tester work?
Simply enter your regex pattern and flags, then test it against your input string. Matches will be highlighted instantly.
⚠️ What happens if I enter an invalid regex?
If your regex pattern is invalid, the tool will show an error message so you can quickly fix it.
🌍 Can I test regex with different flags?
Yes, you can add flags like g (global), i (case-insensitive), and m (multiline) to adjust how the regex behaves.
What Are Regular Expressions?
Regular expressions (regex or regexp) are sequences of characters that define search patterns. They are one of the most powerful tools in a developer's toolkit, used for searching, matching, and manipulating text. Every major programming language supports regular expressions, including JavaScript, Python, Java, Go, and PHP. Regex patterns can validate user input, extract data from strings, perform search-and-replace operations, and parse complex text formats like log files or markup languages.
Basic Regex Syntax
Understanding the fundamental building blocks of regex is essential for writing effective patterns:
.(dot) matches any single character except a newline.*matches the preceding element zero or more times.+matches the preceding element one or more times.?matches the preceding element zero or one time (makes it optional).[abc]matches any one character inside the brackets (character class).[^abc]matches any character NOT inside the brackets.^anchors the match to the start of the string or line.$anchors the match to the end of the string or line.\dmatches any digit (equivalent to[0-9]).\wmatches any word character (letters, digits, and underscore).(abc)groups characters together and captures the match.
Common Regex Patterns Quick Reference
| Purpose | Pattern | Example Match |
|---|---|---|
| Email Address | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | user@example.com |
| URL | https?:\/\/[\w.-]+\.[a-z]{2,}[\/\w.-]* | https://example.com/path |
| US Phone Number | \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} | (555) 123-4567 |
| IPv4 Address | \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | 192.168.1.1 |
| Hex Color Code | #[0-9a-fA-F]{3,6} | #FF5733 |
| Date (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} | 2026-01-15 |
| Strong Password | (?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,} | MyPass1word |
Regex Flags Explained
Flags modify how the regex engine interprets and applies your pattern:
g(global) - Finds all matches instead of stopping after the first one.i(case-insensitive) - Makes the pattern match regardless of letter casing.m(multiline) - Makes^and$match the start and end of each line, not just the entire string.s(dotAll) - Makes the dot.match newline characters as well.u(unicode) - Enables full Unicode matching, treating surrogate pairs as single characters.
When writing regex patterns, start simple and build up complexity incrementally. Test each part of your pattern separately before combining them. Be mindful of greedy vs lazy matching: by default, quantifiers like * and + are greedy and will match as much text as possible. Adding ? after them makes them lazy, matching the minimum amount. For production code, always consider edge cases and test your regex against a variety of valid and invalid inputs.