Regex Tester

Write a regular expression, paste some text and see every match highlighted instantly, with capture groups, named groups and a replace preview.

Free, no sign-upRuns in your browserUpdated November 2026
//g
Matches highlighted
Ready.
Replace preview
Match details
#MatchIndexGroups

How to use the Regex Tester

  1. Type your regular expression without the surrounding slashes, for example \d{3}-\d{4}.
  2. Tick the flags you need: g for all matches, i to ignore case, m for line-by-line anchors and so on.
  3. Paste your test string. Matches are highlighted as you type, and the status bar shows the count and time taken.
  4. Check the match details table for each match’s position, numbered capture groups and named groups.
  5. 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

TokenMeaning
.Any character except a line break (any character with the s flag)
\d / \DDigit 0–9 / not a digit
\w / \WWord character [A-Za-z0-9_] / not a word character
\s / \SWhitespace (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)
\bWord 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|bAlternation: 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): a also matches A.
  • 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

TokenInserts
$&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 as a+.
  • 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?
It uses the JavaScript (ECMAScript) engine built into your browser, so results match Node.js and all modern browsers. Most everyday syntax is shared with PCRE, Python and Java, but features such as possessive quantifiers, atomic groups and inline modifiers are not available in JavaScript.
Why does my pattern only find one match?
Without the 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?
The pattern took too long on your text, which almost always means catastrophic backtracking caused by nested quantifiers such as (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?
Escape it with a backslash: \. 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?
Named groups, written (?<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?
No. Matching runs entirely in your browser inside a Web Worker. Only the pattern, flags and replacement are kept in the page URL so you can share them; the test string is not.

Last reviewed November 2026. Results are estimates for information only — see our disclaimer.