Developer tool

Regex Tester

Test JavaScript regular expressions live: highlighted matches, capture groups, named groups, replace preview, flags and a built-in cheat sheet.

Free, no sign-up. Runs in your browser; nothing is uploaded.

Pattern

Flags
Examples:

Test string

Highlighted matches

2 matches
Contact sales@example.com or support+uk@mail.example.co.uk. Not an email: user@ or @host.com

Match details

Matches
2
First match at
8
Capture groups
0
Named groups
0
  1. #1"sales@example.com"index 8-25, line 1, col 9
  2. #2"support+uk@mail.example.co.uk"index 29-58, line 1, col 30

Replace preview

Turn this on to preview a replacement using $1, $& or $<name>.

Notes on safety

Everything runs in your browser. Results stop at 5,000 matches. A pattern with nested quantifiers such as (a+)+$ can still take very long on certain inputs (catastrophic backtracking); if the page stops responding, reload it and simplify the pattern.

Regex cheat sheet

Anchors

^Start of input (or line with m)
$End of input (or line with m)
\bWord boundary
\BNot a word boundary

Character classes

.Any character except newline (any with s)
\d \DDigit / non-digit
\w \WWord character / non-word
\s \SWhitespace / non-whitespace
[abc]Any of a, b, c
[^abc]None of a, b, c
[a-z]Range
\p{L}Unicode letter (needs u flag)

Quantifiers

*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,}n or more
{n,m}Between n and m
*? +? ??Lazy (as few as possible)

Groups

(abc)Capture group, numbered from 1
(?<name>abc)Named capture group
(?:abc)Non-capturing group
a|bAlternation: a or b
\1 \k<name>Back-reference

Lookaround

(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Flags

gGlobal: find all matches
iIgnore case
mMultiline anchors
sDot matches newline
uUnicode mode
ySticky: match only at lastIndex
dCapture group indices

Escapes

\n \t \rNewline, tab, carriage return
\. \* \\Literal special character
\u00e9Unicode code unit
\x41Hex character code

Replacement tokens

$1 $2Captured group
$<name>Named group
$&Whole match
$$Literal dollar sign

How to use the regex tester

Testing a pattern step by step

Type your expression into the pattern box, set the flags, then paste or type sample text. Matches are highlighted immediately, with the count and a detailed list underneath. Start with the one-click examples if you want to see how a good pattern looks.

Reading the results

  • Highlighted text shows every match, alternating two shades so neighbouring matches stay distinct. Empty matches appear as a thin marker.
  • Match details list each match with its position, line and column, every numbered group and every named group. A group that did not take part shows as undefined.
  • Replace preview applies your replacement to the whole text so you can check a search-and-replace before running it in code.

Flags worth knowing

  1. g finds all matches, not just the first.
  2. i ignores letter case.
  3. m makes ^ and $ match at each line.
  4. s lets the dot match newlines.
  5. u turns on full Unicode handling, needed for \p{L} and emoji.
  6. y is sticky: each match must start exactly where the last one ended.

Writing patterns that behave

  • Anchor patterns with ^ and $ when validating a whole value, such as a form field.
  • Prefer specific classes ([0-9], \d) over a greedy .*, which swallows more than you expect.
  • Use lazy quantifiers (.*?) to stop at the first closing delimiter.
  • Use non-capturing groups (?:...) when you only need grouping, to keep group numbers tidy.
  • Escape the special characters . * + ? ( ) [ ] { } | \ ^ $ when you mean them literally.

Avoiding slow patterns

Nested repetition such as (a+)+ can trigger catastrophic backtracking, where the engine tries an exponential number of paths. Keep alternations distinct, avoid repeating a group that can itself match the same text, and test with long, almost-matching input. Never trust a regular expression alone to validate complex formats such as full email addresses; combine it with a sensible length limit and server-side checks.

Frequently asked questions

Which regular expression flavour does this use?

It uses your browser's JavaScript (ECMAScript) engine, so results match what you will get in Node.js, React or any web code. Other languages differ in details such as lookbehind support, possessive quantifiers and inline flags.

Why do I only see one match?

Without the g (global) flag a regular expression stops after the first match. Switch on g to find every match in the text.

What happens with empty matches?

Patterns like x* or ^ can match zero characters. The tester steps forward after each empty match so it never loops forever, and shows them as thin markers in the preview and as "(empty match)" in the list.

How do I use named groups in a replacement?

Write the group as (?<year>\d{4}) in the pattern and reference it as $<year> in the replacement. Numbered groups use $1, $2 and the whole match is $&.

Can a bad pattern freeze the page?

Patterns with nested quantifiers, such as (a+)+$, can take exponential time on some inputs. This tool caps results at 5000 matches but cannot interrupt a single slow match, so keep patterns simple and anchored.

Is my text uploaded anywhere?

No. Matching runs entirely in your browser and nothing is sent or stored, so it is safe to test against logs or private data.