Skip to content

Regex tester

Write a regular expression, paste some test text and see every match highlighted as you type, with capture groups, positions and a replacement preview.

  • Free, no limits
  • No sign-up
Everything happens in your browser; your data is never uploaded.
  • ✓ Free
  • ✓ No sign-up
  • ✓ Nothing uploaded

Next step

What to do next

How to use it

  1. Type your pattern between the slashes, or start from an example.
  2. Tick the flags you need (g, i, m, s, u).
  3. Paste your test text and watch the matches highlight.
  4. Optionally test a replacement with $1 or $<name>.
Try it now

How the tester works

The tester runs your pattern with the JavaScript (ECMAScript) regex engine, the same one built into every browser and Node.js. As you type, it shows:

  • every match highlighted in the test text,
  • a table with the position (index) of each match and its capture groups, named or numbered,
  • the number of matches and how long the search took,
  • an optional replacement preview, so you can check str.replace() before you put it in code.

The search runs in a separate background thread (a Web Worker) with a 2-second limit. A badly written pattern cannot freeze the page; it is stopped, and you get a hint to simplify it. Your pattern and text never leave your browser.

Flags

FlagNameEffect
gglobalFind all matches, not just the first
iignore casea matches A
mmultiline^ and $ match at the start and end of every line
sdotAll. also matches line breaks
uunicodeFull Unicode support, needed for \p{L} and emoji

Without g, only the first match is shown, just like RegExp.exec() in JavaScript.

Cheat sheet

PatternMatches
\d \w \sdigit, word character (letter, digit, _), whitespace
\D \W \Sthe opposite of each
.any character except a line break
[abc] [^abc] [a-z]one of, none of, a range
* + ?0 or more, 1 or more, 0 or 1
{3} {2,5}exactly 3, from 2 to 5
*? +?lazy versions: match as little as possible
^ $ \bstart, end, word boundary
(…) (?:…)capture group, non-capturing group
(?<name>…)named group, used as $<name> in replacements
a|ba or b
(?=…) (?!…) (?<=…) (?<!…)lookahead and lookbehind
\p{L}any letter in any language (needs u)

Example: reformat dates with named groups

The default example finds ISO dates and swaps them to the US format:

  • Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) with the g flag
  • Text: The contract starts on 2026-11-02 and runs until 2027-01-31.
  • Replacement: $<month>/$<day>/$<year>
  • Result: The contract starts on 11/02/2026 and runs until 01/31/2027.

In replacements, $& inserts the whole match, $1, $2 the numbered groups and $<name> a named group. The built-in examples also cover email addresses, US phone numbers like (555) 123-4567, ZIP and ZIP+4 codes, and Unicode words.

Avoiding catastrophic backtracking

Some patterns take exponential time on certain inputs. The classic case is a nested quantifier such as (a+)+$ run against aaaaaaaaaaaaaaaaaaaaaaaa!: the engine tries every way of splitting the a's between the inner and outer + before giving up. In production, this is a real denial-of-service risk (ReDoS).

To stay safe:

  • avoid quantifiers inside quantified groups, like (\w+)*,
  • make alternatives mutually exclusive, so (a|a)* cannot match the same text two ways,
  • prefer specific classes like [^"]* over .*.

If the tester stops your search after 2 seconds, that is the warning sign.

Testing patterns before you ship them

A few habits save a lot of debugging:

  • Test the failures too. Paste text that should not match, such as an email address without a domain or a ZIP code with four digits, and make sure nothing is highlighted.
  • Anchor validation patterns. For checking a whole input, wrap the pattern in ^…$. Without anchors, \d{5} happily matches the first five digits of 123456789.
  • Escape special characters. To match a literal dot, plus or parenthesis, write \., \+ or \(.
  • Remember string escaping. In JavaScript source code, a pattern written as a string needs doubled backslashes: new RegExp("\\d+"). A regex literal /\d+/ does not.
  • Keep it readable. If a pattern grows beyond one line, split the job into two simpler patterns or add a comment in your code explaining each part.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), as in browsers and Node.js. PHP (PCRE), Python and Java are similar but differ in some features, such as possessive quantifiers and inline flags.

How do I see capture groups?

Matches are listed in a table under the highlighted text, with each numbered or named group and its value.

How do I test a replacement?

Tick Test a replacement and type the replacement string. Use $1, $<name> or $& to insert groups or the whole match.

Why did my regex time out?

The pattern probably backtracks too much, often because of nested quantifiers like (a+)+. Simplify it or make it more specific.

Is my text uploaded?

No. Matching runs in a background thread in your own browser.

Last updated: November 12, 2026

Recommended

Similar tools

If Regex tester helped, you may need these too.

See all in category →

People also use