LocalDevTools

Regex Tester

Write a regular expression and see every match highlighted as you type, with capture groups and a replace preview. Runaway patterns are stopped automatically so the page never freezes.

Matches highlighted
Replace result

Runs entirely in your browser. Your input is never uploaded or stored on a server.

How to use the regex tester

  1. Type your pattern between the slashes. Don't add the surrounding / characters yourself.
  2. Pick flags with the checkboxes or type them in the small box. Without g, only the first match is found.
  3. Paste sample text. Matches are highlighted live, and the table lists each match with its position and capture groups.
  4. Use the replace box to preview String.prototype.replace: $1 inserts group 1, $<name> a named group and $& the whole match.

Quick reference

\d \w \sdigit, word character [A-Za-z0-9_], whitespace (uppercase versions negate)
.any character except line breaks (unless the s flag is on)
* + ? {2,5}0 or more, 1 or more, optional, between 2 and 5. Add ? to make them lazy: .*?
^ $ \bstart, end, word boundary
(…) (?:…) (?<n>…)capture group, non-capturing group, named group
(?=…) (?!…) (?<=…) (?<!…)lookahead, negative lookahead, lookbehind, negative lookbehind
[abc] [^abc] [a-z]character set, negated set, range

Examples

Match an ISO date and capture its parts

(\d{4})-(\d{2})-(\d{2})

On Released 2026-03-14 this gives groups 2026, 03 and 14. Replace with $3/$2/$1 to get 14/03/2026.

Find duplicated words

\b(\w+)\s+\1\b

With flags gi, this finds typos like "the the" using the backreference \1.

Lines that do not contain a word

^(?!.*error).*$

With flags gm, this matches every line that does not contain error.

JavaScript vs Python vs PCRE

This tester uses your browser's JavaScript engine. Most syntax is shared, but a few differences cause real bugs when you copy a pattern between languages:

  • Named groups: JavaScript and .NET use (?<name>…). Python's re uses (?P<name>…). PCRE/PHP accepts both.
  • Flags: JavaScript flags go after the pattern (/x/i). In Python you pass re.IGNORECASE or use inline (?i), which JavaScript does not support everywhere.
  • Possessive quantifiers and atomic groups (a++, (?>…)) work in PCRE and recent Python, but not in JavaScript.
  • Lookbehind: JavaScript allows variable-length lookbehind; Python's re requires fixed-length lookbehind and PCRE historically did too.
  • $ at the end: in Python and PCRE, $ also matches before a final newline; in JavaScript it does not.

Avoiding catastrophic backtracking

Nested quantifiers such as (a+)+$ can take exponential time on input that almost matches. This is a real cause of production outages (ReDoS). This page runs your pattern in a background worker and stops it after one second, then tells you. If that happens, remove nested quantifiers or make the inner part more specific.

Frequently asked questions

Which regex flavor does this tester use?

The JavaScript (ECMAScript) engine built into your browser, the same ECMAScript regex syntax used by Node.js, Deno and every modern browser. The section above lists the differences that matter when porting to Python or PCRE.

Why does my pattern only find one match?

Turn on the g (global) flag. Without it, JavaScript stops after the first match.

Why is a backslash disappearing when I copy the regex into code?

In a string literal, backslashes must be escaped, so \d becomes "\\d". In JavaScript you can avoid this with a regex literal /\d+/, and in Python with a raw string r"\d+".

How do I match across multiple lines?

Use the s (dotAll) flag so . matches newlines, and the m flag if you want ^ and $ to match at each line rather than only at the start and end of the text.

Is there a limit on text size?

No hard limit, but highlighting is capped at the first 1,000 matches to keep the page responsive. The match count still reports the total.

Related tools

Last updated: