Regex Tester
Test JavaScript regular expressions in real time. See matches, capture groups, and flags as you type. Pattern and text stay in your browser.
| # | Match | Index | Groups |
|---|---|---|---|
| 1 | hello@utilo.fun | 6–21 | $1: hello $2: utilo.fun |
| 2 | admin@example.com | 25–42 | $1: admin $2: example.com |
Use this free regex tester to debug JavaScript regular expressions in real time. Edit the pattern, toggle flags, and see every match highlighted directly in your text — plus a table of capture groups and positions. It runs entirely in your browser, so pattern and data stay on your device.
How to use it
No account, no upload — it all happens on your device.
Quick reference: common patterns
Copy-paste recipes for everyday matching.
| Goal | Pattern | Notes |
|---|---|---|
| Match an integer | ^-?\d+$ | Optional leading minus; one or more digits. |
| Match an email (loose) | [\w.+-]+@[\w-]+\.[\w.-]+ | Good enough for UI hints. For true validation, send a verification email. |
| Strip surrounding whitespace | ^\s+|\s+$ | Use with the global flag and replace with empty. |
| Capture a URL | (https?)://([\w.-]+)(/\S*)? | Groups: protocol, host, optional path. |
| ISO date | \d{4}-\d{2}-\d{2} | Won't reject 2024-13-99 — just checks shape. |
| Whole-word match | \bword\b | \b is a zero-width word boundary. |
JavaScript regex vs PCRE — quick notes
Patterns that travel and patterns that don't.
- Named groups. JS supports
(?<name>…)since ES2018. Most modern flavors do too, but syntax differs in older PCRE. - Lookbehind. JS supports
(?<=…)and(?<!…)since ES2018. Safari shipped it late — fine in 2024+. - Unicode property escapes. JS needs the
uflag for\p{L},\p{Emoji}, etc. Withoutu,\pis just a literalp. - Possessive quantifiers and atomic groups. PCRE has them; JavaScript does not. Workarounds: rewrite to remove ambiguity, or use lookahead tricks.
- Recursion / subroutines. Not in JS regex. Parse with a real parser for nested structures like JSON.
Catastrophic backtracking
A regex engine that supports backtracking can take exponential time on certain patterns against certain inputs. The classic shape is nested ambiguous quantifiers like (a+)+ applied to a long string of as followed by a non-match. Each a doubles the work the engine does before failing.
Avoiding it:
- Anchor your patterns.
^pattern$rules out a lot of failed match starts. - Make alternatives mutually exclusive.
(a|b)+is fine;(a|aa)+can blow up. - Replace nested quantifiers with a single quantifier on a character class when possible.
[ab]+instead of(a|b)+. - When the input is untrusted (user-submitted search terms, logs), cap input size or run regex matching with a timeout in a Worker.