Regular expressions are powerful but notoriously hard to get right. Testing them in real-time with match highlighting saves hours of debugging. Here’s how.
How to Test Regex Online
- Open our Regex Tester
- Enter your regex pattern in the pattern field
- Set flags (g = global, i = case-insensitive, m = multiline)
- Paste your test string below
- See matches highlighted instantly as you type
Essential Regex Patterns (Cheat Sheet)
Common Patterns
| Pattern | Matches | Example |
|---|---|---|
\d+ |
One or more digits | “123”, “42” |
\w+ |
Word characters | “hello”, “user_1” |
[a-zA-Z]+ |
Letters only | “Hello”, “world” |
\s+ |
Whitespace | spaces, tabs, newlines |
.+ |
Any character (except newline) | anything |
Practical Examples
Email validation:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
URL matching:
https?://[\w.-]+\.[a-zA-Z]{2,}[/\w.-]*
Phone number (US):
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
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])
Regex Flags Explained
| Flag | Name | What it does |
|---|---|---|
g |
Global | Find all matches, not just the first |
i |
Case-insensitive | Treat upper and lower case as same |
m |
Multiline | ^ and $ match line starts/ends |
s |
Dotall | . matches newline characters too |
Common Regex Mistakes
- Forgetting to escape special characters —
.means “any character,” not a literal dot. Use\.for a literal dot. - Greedy vs lazy matching —
.*is greedy (matches as much as possible). Use.*?for lazy (matches as little as possible). - Not anchoring patterns — Use
^and$to match the full string, not just a substring. - Over-complex patterns — If your regex is longer than 50 characters, consider splitting the validation into multiple steps.
Frequently Asked Questions
What regex flavor does this tool use?
JavaScript regex (ECMAScript). This is the same engine used in browsers, Node.js, and most web frameworks.
Can I test capture groups?
The tool highlights all matches. For detailed capture group inspection, check your browser’s DevTools console.
How do I match across multiple lines?
Add the m flag for multiline mode, and use [\s\S] instead of . to match everything including newlines.
Related Tools
- Text Diff Checker — Compare regex outputs
- Case Converter — Transform matched text
- URL Encoder — Encode regex results for URLs