How to use the Regex Tester
- Type your regular expression without the surrounding slashes, for example
\d{3}-\d{4}. - Tick the flags you need:
gfor all matches,ito ignore case,mfor line-by-line anchors and so on. - Paste your test string. Matches are highlighted as you type, and the status bar shows the count and time taken.
- Check the match details table for each match’s position, numbered capture groups and named groups.
- Enter a replacement to preview the result of
String.replace, then copy it or copy the regex literal for your code.
How this regex tester works
The tester uses your browser’s own JavaScript (ECMAScript) regular-expression engine, the same one that runs String.prototype.match, matchAll and replace in your code. What you see here is exactly what Node.js, Chrome, Firefox and Safari will do. Matching runs in a separate Web Worker: if a pattern takes longer than one second it is stopped, so a runaway expression cannot freeze the page. Your text never leaves your device.
Patterns written for other engines (PCRE in PHP, Python’s re, .NET, Java) are mostly compatible, but some features differ: JavaScript has no possessive quantifiers or atomic groups, and lookbehind support is newer. Test in the engine your code will actually use.
Regex cheat sheet
| Token | Meaning |
|---|---|
. | Any character except a line break (any character with the s flag) |
\d / \D | Digit 0–9 / not a digit |
\w / \W | Word character [A-Za-z0-9_] / not a word character |
\s / \S | Whitespace (space, tab, line break) / not whitespace |
[abc] / [^abc] | Any one of a, b, c / anything except a, b, c |
[a-z] | Character range |
^ / $ | Start / end of the string (of each line with the m flag) |
\b | Word boundary |
* + ? | 0 or more, 1 or more, 0 or 1 |
{3} {2,5} {2,} | Exactly 3, between 2 and 5, 2 or more |
*? +? | Lazy versions: match as little as possible |
(abc) | Capturing group, referenced as $1 in replacements and \1 in the pattern |
(?<name>abc) | Named group, referenced as $<name> and \k<name> |
(?:abc) | Non-capturing group |
a|b | Alternation: a or b |
(?=x) / (?!x) | Lookahead: followed / not followed by x |
(?<=x) / (?<!x) | Lookbehind: preceded / not preceded by x |
\p{L} | Any Unicode letter (requires the u flag) |
Flags
- g (global): find every match instead of stopping at the first.
- i (ignore case):
aalso matchesA. - m (multiline):
^and$match at the start and end of each line. - s (dotAll):
.also matches line breaks. - u (unicode): treat the pattern as Unicode code points and enable
\p{…}property escapes. - y (sticky): match only at the current position, which is useful for tokenizers.
Worked example: extracting email parts
The default pattern (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+) captures the part before the @ as user and the domain as domain. The domain part requires at least one dot, so hello@ and @example.com are not matched. The replacement [$<user> at $<domain>] turns support@example.com into [support at example.com]. Real-world email validation is far more complex than any short regex; use this pattern to find likely addresses, not to reject user input.
Replacement patterns
| Token | Inserts |
|---|---|
$& | The whole match |
$1, $2… | Numbered capture group |
$<name> | Named capture group |
$` / $' | Text before / after the match |
$$ | A literal dollar sign |
Avoiding catastrophic backtracking
JavaScript’s engine is a backtracking engine. Patterns with nested or overlapping quantifiers, such as (a+)+$, (\w+\s?)*$ or (.*,)*, can try an exponential number of combinations when the input almost matches. On a few dozen characters this can take minutes, and on a server it becomes a denial-of-service risk (often called ReDoS). To avoid it:
- Do not nest quantifiers on the same characters;
(a+)+means the same asa+. - Prefer specific character classes such as
[^,]*over.*. - Anchor patterns with
^and$when you validate whole strings. - Limit input length before running user-supplied text through complex patterns.
For simple literal replacements across many lines you may not need regex at all: use your editor’s plain find and replace. To compare text before and after a replacement, use the diff checker.
Frequently asked questions
Which regex flavor does this tester use?
Why does my pattern only find one match?
g (global) flag, JavaScript stops after the first match. Tick g to find all matches. In your own code, use matchAll or a g-flagged regex with replace.Why was my regex stopped after one second?
(a+)+ or (.*)*. Rewrite the repeated part so that each character can be matched in only one way.How do I match a literal dot, slash or bracket?
\. matches a dot, \( a parenthesis and \[ a bracket. You do not need to escape / here because you type the pattern without slashes, but you do inside a /…/ literal in code.What are named capture groups?
(?<name>…), work like numbered groups but can be read by name: match.groups.name in code and $<name> in replacements. They make long patterns easier to read and maintain.Is my test text sent to a server?
Last reviewed November 2026. Results are estimates for information only — see our disclaimer.