Regex Tester

Enter a pattern and flags, paste your test string, and see matches highlighted live — with capture groups, a match count, and a replace preview. Runs entirely in your browser.

Dialect: JavaScript (ECMAScript) RegExp — behavior may differ from PCRE, Python re, or other regex engines.

Enter a pattern to start matching.

Matches will be highlighted here once you enter a test string.

Testing regular expressions in JavaScript

A regular expression (regex) is a compact pattern for finding, validating, or replacing text. This tester runs your pattern with the browser's own RegExp engine and updates as you type: matches are highlighted, each is listed with its position and captured groups, and a live count shows how many were found. Because it uses the native engine, what you see here is exactly what the same pattern will do in JavaScript code.

Enter the pattern without the surrounding slashes, tick the flags you need, and paste your text into the test box. The dialect matters: this tool tests the JavaScript (ECMAScript) flavour, which differs from PCRE (used by PHP and many command-line tools) and from Python's re module. Features such as recursive patterns, atomic groups, and possessive quantifiers do not exist in JavaScript, so a pattern copied from another language may behave differently here.

What the flags do

FlagNameEffect
gGlobalFind every match, not just the first
iIgnore caseTreat A and a as the same
mMultiline^ and $ match each line's start and end
sDotallThe dot also matches newline characters
uUnicodeFull code-point matching and \p{...} escapes
yStickyMatch only at the current position
Example 1 — Matching dates. The pattern \d{4}-\d{2}-\d{2} run against "Launch 2026-07-26, review 2026-08-10" finds both dates. With the g flag the match count reads 2; without g, only the first date is found.
Example 2 — Named groups. The pattern (?<year>\d{4})-(?<month>\d{2}) run against "2026-07" captures group 1 (year) as 2026 and group 2 (month) as 07. The tester lists both the numbered and the named groups for every match.
Example 3 — Replace order. Using that same pattern with the replacement $<month>/$<year> rewrites "2026-07" as "07/2026". Referring to groups by name is often clearer than $1 and $2 in longer patterns.

The most common surprise

By far the most frequent confusion is a replace that changes only the first match. In JavaScript, replacing every occurrence requires the g flag — without it, only the first match is replaced, and that is the language rule, not a bug. The replace preview here mirrors that exactly, and a hint appears reminding you to add g whenever your pattern would otherwise stop after one substitution.

Handy tokens and a privacy note

Your pattern, test string, and replacement never leave your browser — nothing is uploaded, and only your last input is kept locally for convenience.

Sources & further reading

Frequently asked questions

How do I test a regular expression online for free?

Type or paste your pattern into the pattern field (without the surrounding slashes), tick the flags you need — g for global, i for case-insensitive, and so on — then paste your text into the test string box. This regex tester matches live as you type: every match is highlighted in the preview, listed with its start index and captured groups below, and the match count updates instantly. For example, entering the pattern \b\w+@\w+\.\w+\b against "Contact us at hello@example.com or sales@example.org" highlights both email addresses immediately, no submit button needed.

What do the regex flags g, i, m, s, u, and y mean in JavaScript?

g (global) finds every match instead of stopping at the first; i (ignore case) makes A and a equivalent; m (multiline) makes ^ and $ match the start and end of each line instead of only the whole string; s (dotall) lets . match newline characters too; u (unicode) enables full Unicode code-point matching (needed for things like emoji or astral characters and for \p{...} Unicode property escapes); and y (sticky) forces the match to start at exactly the current position (lastIndex) rather than scanning ahead. This tool lets you toggle each one and see the effect on your matches immediately.

Why does my regex only replace the first match?

In JavaScript, String.prototype.replace() only replaces every occurrence when the regular expression has the g (global) flag — without it, only the first match is replaced, which is standard ECMAScript behavior, not a bug. This regex tester mirrors that exact rule: the replace preview shows what your pattern and replacement actually produce with your current flags, and a hint appears reminding you to check g if you expected every match to change. Turn on g and the preview updates to show every match replaced.

How do named capture groups like (?<year>\d{4}) work in JavaScript regex?

Wrapping part of a pattern in (?<name>...) creates a named capture group alongside the normal numbered groups — for example (?<year>\d{4})-(?<month>\d{2}) matched against "2026-07" captures group 1 / "year" as 2026 and group 2 / "month" as 07. Named groups can also be referenced in a replacement string as $<year>, which is often clearer than $1 in longer patterns. This tester lists both the numbered groups and the named groups for every match, so you can confirm the capture works before using it in real code.

Is my regex pattern or test string sent to a server, and does this match every regex dialect?

No — everything runs locally using your browser's built-in RegExp engine; your pattern, test string, and replacement text are never uploaded or stored anywhere, and nothing is saved except your last input in your own browser's local storage for convenience. This tool tests the JavaScript (ECMAScript) regex dialect specifically, so a pattern that relies on PCRE-only or Python re-only features (like recursive patterns, atomic groups, or possessive quantifiers) may behave differently here than in those languages — check your target language's own documentation if you are writing regex for something other than JavaScript.