Skip to content
MoneyDeck

Regex Tester

Test JavaScript regular expressions live, with matches, groups and replace

Updated · Free, no signup

Enter the pattern without surrounding slashes.

g = global, i = ignore case, m = multiline, s = dot matches newline, u = unicode, v = unicode sets, y = sticky, d = indices.

Use $1, $<name>, $& for the match, $$ for a literal $.

Matches found

2

Pattern status

Valid — /(\d{3})-(\d{4})/g

First match

555-1234

First match position

5

0-based character index; −1 when there is no match.

Capture groups in pattern

2

Text with matches highlighted

Call ⟦555-1234⟧ or ⟦555-9876⟧ today. Fax: 5551234.

Replace result

Call 555-XXXX or 555-XXXX today. Fax: 5551234.

Matches and capture groups

#IndexMatchGroups
15555-1234$1=555, $2=1234
217555-9876$1=555, $2=9876

About the Regex Tester

This regex tester runs a JavaScript regular expression against your sample text and shows exactly what it matches. Every match is listed with its position and capture groups (including named groups), matches are highlighted inline with ⟦ ⟧ markers, and an optional replacement string previews the result of String.replace — so you can build and debug a pattern before pasting it into code.

Flags work just as they do in JavaScript: g finds all matches instead of the first, i ignores case, m makes ^ and $ match at line breaks, s lets . match newlines, u enables full Unicode, y makes the match sticky and d records group indices. Replacement strings support $1, $2, $<name>, $& (the whole match) and $$ for a literal dollar sign.

It suits web developers writing form validation, data engineers cleaning log files, and anyone learning regex syntax. Patterns are executed by your browser’s own engine, so behavior matches Chrome, Firefox, Safari and Node.js; syntax that only other flavours support (such as PCRE possessive quantifiers) will be reported as an error. The tester cannot interrupt a pattern once it starts, so a pattern prone to catastrophic backtracking, such as (a+)+$ on a long non-matching string, can freeze the tab until the browser stops the script.

With the default inputs, the matches found is 2. Change any value above to recalculate instantly.

How to use the regex tester

  1. 1Enter your pattern without the surrounding / slashes.
  2. 2Add flags — usually g to find every match, plus i to ignore case.
  3. 3Paste the text you want to test against.
  4. 4Check the match count, highlighted text and the groups table.
  5. 5Optionally enter a replacement to preview a find-and-replace.

Formula and method

The pattern and flags are compiled with the browser’s built-in RegExp engine (ECMAScript), then applied to the test text with exec(). With the g (or y) flag the search continues from lastIndex after each match; when a match is empty the index is advanced by one character (or one code point in u mode) so the loop always terminates. Each match records its 0-based starting index and any numbered or named capture groups; groups that did not participate are shown as ∅.

The replacement preview uses String.prototype.replace with the same RegExp, so $1…$99, $<name>, $&, $` , $' and $$ behave exactly as they will in your code. Without g only the first occurrence is replaced. Up to 1,000 matches are collected.

Worked examples

Find phone numbers and mask them

The pattern (\d{3})-(\d{4}) matches three digits, a hyphen and four digits, so it finds 555-1234 at position 5 and 555-9876 at 17 but skips 5551234, which has no hyphen. Replacing with $1-XXXX keeps the first group and masks the rest.

Reformat dates with named groups

Named groups make the pattern self-documenting. Both ISO dates match, and the replacement $<day>/$<month>/$<year> rewrites them as 29/09/2026 and 03/10/2026 without touching the rest of the sentence.

Whole-word, case-insensitive search

The \b word boundaries stop "CATalog" from matching, and the i flag makes Cat and cat equivalent, so there are 3 matches. With g, all three are replaced by "dog".

Same search without the g flag

Dropping g is a classic bug: exec and replace stop after the first match, so only the leading "Cat" becomes "dog" and the other two stay unchanged.

Frequently asked questions

Which regex flavour does this tester use?+

JavaScript (ECMAScript) regular expressions, executed by your browser. That matches Node.js, TypeScript and front-end code. Most everyday syntax is shared with Python, PCRE and Java, but features like possessive quantifiers or \A anchors are not supported.

Why does my regex only match once?+

Without the g (global) flag, JavaScript stops after the first match for exec(), match() and replace(). Add g to the flags to find or replace every occurrence.

How do I match a literal dot, plus sign or bracket?+

Escape it with a backslash: \. matches a dot, \+ a plus, \( a parenthesis and \[ a bracket. Inside a character class like [.+] most symbols are already literal.

What is the difference between .* and .*?+

.* is greedy and grabs as much text as possible before backtracking, while .*? is lazy and takes as little as possible. For "<b>x</b><b>y</b>", <b>.*</b> matches the whole string but <b>.*?</b> matches just <b>x</b>.

How do I use capture groups in a replacement?+

Refer to numbered groups with $1, $2 and so on, to named groups with $<name>, and to the whole match with $&. For example, replacing (\w+) (\w+) with "$2 $1" swaps two words.

Can a regex freeze my browser?+

Yes — nested quantifiers such as (a+)+$ can cause catastrophic backtracking on long non-matching input. If a pattern hangs, make quantifiers more specific or anchor the pattern.

Related tools