Regex Tester
Test regular expressions against text with real-time match highlighting.
What You Can Do Here
- See matches highlighted in real time as you type your pattern
- View capture groups and their values for each match
- Toggle all JavaScript flags (g, i, m, s, u, y)
- Get match count and position info for every result
- Access a quick-reference cheatsheet for common patterns
Regex Cheatsheet
- . - Matches any character except newline
- \d - Any digit (0-9). \D matches non-digits.
- \w - Any word character (letters, digits, underscore). \W matches non-word characters.
- \s - Any whitespace (space, tab, newline). \S matches non-whitespace.
- * - Zero or more of the previous token
- + - One or more of the previous token
- ? - Zero or one (makes something optional)
- {n,m} - Between n and m occurrences
- [abc] - Any one character from the set
- [^abc] - Any character NOT in the set
- (group) - Capture group. Use (?:group) for non-capturing.
- ^ - Start of string. $ - End of string.
- | - OR operator. "cat|dog" matches either word.
Common Regex Patterns
Here are patterns developers reach for all the time:
- Email (basic) - [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
- Phone (US) - \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
- URL - https?:\/\/[\w\-]+(\.[\w\-]+)+[/#?]?.*$
- IP Address - \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Why Your Regex Might Work in One Language but Not Another
Regex has different "flavors." JavaScript, Python (re module), PCRE (PHP, Perl) and .NET all have slightly different syntax and feature sets. Lookbehind support, named groups and Unicode handling all vary. This tool uses JavaScript's regex engine, which is what you'd use in Node.js and browser-based code. If you're writing Python or PHP regex, double-check flavor-specific differences.
How to Use
- Type your regex pattern in the pattern field.
- Set flags - g for global (all matches), i for case-insensitive, m for multiline.
- Paste your test text in the text area below.
- Matches get highlighted instantly. Check capture groups in the results panel.
Frequently Asked Questions
Which regex flavor does this tool use?
JavaScript (ECMAScript) regex. This is the same engine used in all modern browsers and Node.js. If you're writing regex for Python, PHP or .NET, be aware that some features behave differently.
Can I use lookbehind assertions?
As long as your browser supports them. Chrome 62+, Firefox 78+ and Safari 16.4+ all do. Older browsers may not, so check your target audience before shipping lookbehinds in production code.
What do the regex flags mean?
g = global (find all matches, not just the first). i = case-insensitive. m = multiline (^ and $ match at line breaks, not just start/end of string). s = dotAll (dot matches newlines too). u = Unicode mode. y = sticky (matches from lastIndex position only).
Why does my regex work here but fail in Python?
Different regex flavors have different syntax. Python uses the re module with its own rules. For example, JavaScript uses /pattern/flags while Python uses re.compile("pattern", flags). Named groups also use different syntax. Always test in the target language.
Is regex the right tool for parsing HTML?
Almost never. HTML is a nested, recursive structure that regex can't handle properly. Use a DOM parser instead. Regex is great for simple text patterns, validation and search-and-replace tasks on flat text.