How to Test Regular Expressions
Regular expressions are powerful but notoriously hard to get right. A live tester that shows matches as you type is the fastest way to build and debug patterns. This guide shows you how to test regex with real-time feedback.
When You Need a Regex Tester
- Building a pattern to validate emails, URLs, or phone numbers
- Extracting data from log files or API responses
- Writing search-and-replace patterns for code refactoring
- Debugging a regex that doesn't match what you expect
- Learning regex syntax with instant visual feedback
How to Test a Regex
Step 1: Open the tool
Go to the Regex Tester.
Step 2: Enter your pattern
Type your regex between the / delimiters. Set flags using the toggle buttons or type them directly (e.g. gi for global + case-insensitive).
Step 3: Enter test text
Paste the text you want to test against. Matches are highlighted in yellow in real time. The Match Details panel shows each match with its position and capture groups.
Step 4: Test replacements
Enter a replacement string in the Replace field to see a preview. Use $1, $2 to reference capture groups.
Common Patterns
- Email:
[\w.-]+@[\w.-]+\.\w+ - URL:
https?://[^\s]+ - IP address:
\d{1,3}(\.\d{1,3}){3} - Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2} - HTML tag:
<(\w+)[^>]*>
Tips
- Always use the
gflag when you want to find all matches, not just the first one. - Click "Sample" to load an email extraction example that demonstrates capture groups.
- If your regex seems slow, it might have catastrophic backtracking. Simplify nested quantifiers like
(a+)+.
FAQ
What regex flavor does the tool use?
The tool uses JavaScript's built-in RegExp engine. This supports most common regex features including lookahead, lookbehind (in modern browsers), Unicode properties (with the u flag), and named capture groups.
What do the flags mean?
g (global) finds all matches, not just the first. i (case-insensitive) ignores case. m (multiline) makes ^ and $ match line boundaries. s (dotAll) makes . match newlines. u (unicode) enables full Unicode matching.
How do I use group references in replace?
Use $1, $2, etc. to reference capture groups in the replace string. For example, with pattern (\w+)@(\w+) and replace '$2/$1', the input 'user@host' becomes 'host/user'.
Is my data uploaded to a server?
No. All regex testing happens entirely in your browser using JavaScript's native RegExp. Your patterns and test strings never leave your device.
Try It Now
Ready to test? Open the Regex Tester — it works entirely in your browser with no sign-up required.