Regex Tester
GeneratorsTest and debug regular expressions with live matching and explanation. Free, private — all processing in your browser.
Write a pattern, paste some test text, and watch every match light up instantly — with each capture group, its position, and its length listed out so you can see exactly what your regex is grabbing. Toggle the g, m, i, and s flags with a click, load a preset for common patterns (email, URL, IP, phone, hex color, date), or open the cheatsheet to build a pattern piece by piece. There's also a replace mode where you can use $1, $2 for captured groups.
Crucially, this runs on your browser's own JavaScript regex engine — so what you see here is exactly what new RegExp() will do in your code. No server round-trip, no different flavor to trip you up.
What the Regex Tester can do
Live regex matching
See matches highlighted in real-time as you edit the pattern or the test string. No need to click a button. Matches update instantly.
Capture group inspection
Each numbered and named capture group is shown separately, with its content and position. Essential for extracting structured data from text.
Plain-English explanation
The tool explains what each part of your regex does (\d means any digit, + means one or more, etc.). Great for learning regex or reading someone else's pattern.
All JavaScript flags supported
Toggle g (global), i (case-insensitive), m (multiline), s (dotall), u (unicode), y (sticky) and see how each changes the result.
Replace mode
Test find-and-replace operations. Use $1, $2 etc. for capture group references in the replacement string.
Common pattern library
Built-in patterns for email, URL, IP address, phone, credit card, date, hex color, and more. Click to insert and customize.
Error detection
Invalid regex syntax is reported with a clear error message and position. No more silent failures.
Multi-language cheat sheet
Syntax differences between JavaScript, Python re, PHP PCRE, Go regexp, and .NET Regex are noted in the reference panel.
How to use the Regex Tester
- 1
Paste your test string
Drop the text you want to match against — API responses, log lines, user input, or file contents. The tester handles strings up to megabytes in size.
- 2
Write or paste your regex pattern
Enter the regex pattern in the pattern field. Leading and trailing slashes are optional — the tester handles both forms.
- 3
Set flags
Toggle the g, i, m, s, u, y flags depending on what you need. Hover each flag for a description.
- 4
Read the matches
Matches are highlighted in the test string. The sidebar shows each match's position, captured text, and named/numbered groups.
- 5
Use the explanation panel
Click any part of the pattern to see what it does. Great for debugging complex regex or learning regex as you go.
- 6
Test replacement (optional)
Switch to Replace mode to see how your regex transforms the text. Use $1, $2, $<name> to reference capture groups in the replacement string.
When to use the Regex Tester
Input validation
- →Validate email addresses: Check email format before submitting forms. Use a simple pattern like `^[^\s@]+@[^\s@]+\.[^\s@]+$` for most cases — not perfect RFC 5322 compliance, but 99.9% accurate for real emails.
- →Validate URLs: Accept http/https URLs with optional paths and query strings. `^https?:\/\/[^\s]+$` is a good starting point.
- →Validate phone numbers: Country-specific formats like US `^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$` or more permissive international formats.
- →Validate passwords: Enforce complexity rules: `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$` for lowercase, uppercase, digit, and min 8 chars.
- →Validate UUIDs, credit cards, dates: Every common data format has a standard regex. Validate before processing to reject malformed input early.
Text extraction
- →Extract emails from text: Scan documents, logs, or CSV files and pull out every email address with `[\w.+-]+@[\w-]+\.[\w.-]+`.
- →Extract URLs from HTML: Find all href links with `href="([^"]+)"` capturing the URL in group 1.
- →Extract log timestamps: Parse log lines like `2026-05-05T14:23:01Z ERROR ...` with `^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)`.
- →Extract IP addresses: Find IPv4 addresses with `\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b` or IPv6 with a more complex pattern.
Search and replace
- →Rename variables across a codebase: Find `\bgetUserName\b` and replace with `getUsername` while respecting word boundaries to avoid matching substrings.
- →Clean up formatting: Collapse multiple spaces with `\s+` → single space. Remove trailing whitespace with `\s+$` in multiline mode.
- →Normalize quotes and dashes: Convert smart quotes `[“”]` to straight `"`, em-dashes `—` to double-hyphens `--`, etc.
- →Strip HTML tags: `<[^>]+>` removes simple HTML tags. For real-world HTML, use an HTML parser — regex for HTML is a well-known foot-gun.
Log parsing and analysis
- →Parse Apache/Nginx access logs: Extract IP, timestamp, request method, URL, and status code from structured log lines.
- →Extract error stack traces: Find all error messages and their file/line references in application logs.
- →Count and categorize events: Match log patterns by severity, component, or event type to build summaries.
Worked examples
Email validation
Simple but effective email regex. Matches virtually all real email addresses.
Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$ Test: alice@example.com
✓ Match Group 0: alice@example.com
Extract all URLs
Global flag finds all matches, not just the first.
Pattern: https?:\/\/[^\s]+ (flags: g) Test: Visit https://tooleras.com and https://github.com for info
Match 1: https://tooleras.com Match 2: https://github.com
Capture groups
Parentheses capture portions of the match into groups.
Pattern: (\w+)@(\w+\.\w+) Test: contact@tooleras.com
Group 0: contact@tooleras.com Group 1: contact Group 2: tooleras.com
Find and replace with backreference
Swap order using $1, $2 in replacement.
Pattern: (\w+)\s+(\w+) Replace: $2 $1 Test: John Doe
Doe John
Named groups (ES2018+)
Name your groups for clarity in larger patterns.
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Test: 2026-05-05year: 2026 month: 05 day: 05
Lookahead (non-consuming)
Match only if followed by a pattern, without including it.
Pattern: \d+(?= dollars) Test: 50 dollars and 30 euros
Match: 50 (30 skipped because not followed by "dollars")
Case-insensitive search
The i flag matches any case.
Pattern: hello (flags: gi) Test: Hello HELLO hello HeLLo
4 matches (case ignored)
How it works
This is the JavaScript (ECMAScript) regex flavor — the single most important thing to know, because regex is not one language. What works here works in JS, Node, and TypeScript. It does *not* guarantee the same behavior as PCRE (PHP), Python's re, Go, or Java. Practical differences: JS supports lookbehind (?<=...) in modern engines, named groups are (?<name>...), and there's no \A/\Z — use ^/$ with the right flags.
The flags, and why they matter:
- g (global) — without it you only ever get the *first* match. If "only one match shows," this is almost always why.
- m (multiline) — makes ^ and $ match at line breaks, not just string start/end.
- i — case-insensitive. s — lets . match newlines too.
Greedy vs lazy. .* grabs as much as possible; .*? grabs as little. Over-matching is usually a greedy quantifier — add ? to make it lazy.
Capture groups. (...) captures for reuse (shown per match here, and usable as $1 in replace); (?:...) groups without capturing. Named groups (?<year>\d{4}) make matches self-documenting.
Pitfalls and fixes
⚠Only the first match shows up
You're missing the g (global) flag. Without it, regex stops at the first match. Click the g toggle to find them all.
⚠Pattern works here but fails in PHP/Python
This is the JavaScript regex flavor. Advanced features and some escapes differ across PCRE, Python re, and Java. Test in the target language's engine for anything beyond the basics.
⚠A greedy quantifier grabs too much
.* matches as much as it can, often swallowing past what you wanted. Make it lazy with .*? or be more specific about what to stop at.
⚠Catastrophic backtracking hangs the match
Nested quantifiers like (a+)+ on non-matching input can explode into billions of steps. Avoid nesting quantifiers over overlapping character sets; anchor and simplify the pattern.
⚠Unescaped special characters
Characters like . ( ) [ ] { } + * ? ^ $ | \ are operators. To match them literally, escape with a backslash — a literal dot is \. not .
Alternatives and comparisons
JavaScript regex vs PCRE/Python. If you're testing a pattern for a PHP preg_match, a Python script, or a grep, be careful: this tester uses JS semantics. Most basics are identical, but advanced features (recursion, possessive quantifiers, some Unicode property escapes) differ. For JS/Node code, this is exactly right.
Regex vs a real parser. Regex is the wrong tool for nested or recursive structures — HTML, JSON, source code. It can't reliably match balanced tags or brackets, and trying leads to fragile patterns. Parse those with a real parser; use regex for flat, line-oriented text.
"Validating" with regex. A regex email or URL check is an *approximation* — the presets here catch the common shapes, not every RFC-legal address. For truly valid email, the only sure test is sending mail. Use regex to filter obvious junk, not to guarantee correctness.
Regex Tester — FAQ
▶Which regex flavor does this use?
JavaScript (ECMAScript) — the same engine as new RegExp() in the browser and Node. Results match JS/TypeScript exactly. For PHP, Python, or Java, expect small differences in advanced features.
▶Why do only some of my matches appear?
You almost certainly need the g (global) flag. Without it the engine returns only the first match. Toggle g and all matches, with their positions, will list.
▶Is my pattern or test text sent anywhere?
No. Matching runs entirely in your browser using its native regex engine. Nothing is uploaded, so it's safe to test against real data.
▶How do I use captured groups in the replacement?
Turn on Replace and reference groups as $1, $2, and so on (or $<name> for named groups). For example, replacing (\w+)@(\w+) with $2.$1 swaps the two halves.
▶Can I use this to validate emails perfectly?
Not perfectly — no regex can. The email preset catches the common shape and rejects obvious junk, but the only definitive validation is sending a message. Use regex as a first-pass filter.
▶Why does my regex freeze on some input?
Catastrophic backtracking — usually nested quantifiers over overlapping patterns like (a+)+. Rewrite to avoid the nesting and anchor the pattern so the engine can fail fast.
Further reading
- MDN — Regular Expressions — Comprehensive JavaScript regex guide with examples for every feature.
- regex101 — Interactive Regex Tester — Alternative regex tester with flavor-specific support and detailed explanations.
- Regular-Expressions.info — Jan Goyvaerts' comprehensive regex reference site with deep dives.
- RegExr — Community Regex Editor — Browser-based regex editor with a pattern library and community snippets.
- Regex Cheat Sheet — Our regex cheat sheet covering beginner to advanced patterns.
Related tools
All GeneratorsCase Converter
Convert between upper, lower, title, camel, snake, kebab, Pascal, CONSTANT cases
Extract Emails from Text
Extract every email address from pasted text with validation, deduplication, and clean export to CSV or line-separated list.
Extract URLs from Text
Extract every URL from pasted text with deduplication, validation, and export to CSV, JSON, or newline-separated list.
Find and Replace
Find and replace text with regex support, case sensitivity, whole-word matching, and preview of all changes before applying.
JSON Formatter
Format, validate, and beautify JSON instantly in your browser
Regex Generator
Describe what you want to match in plain English and get a working regular expression with tested patterns, flavor-specific variants, and live match testing for multiple languages.
Learn more
Explore more tools
200+ free tools that run in your browser.
Browse all tools →