← Developer

Regex Tester

Test JavaScript regular expressions with live highlighted matches, capture groups, and a replacement preview.

Pattern and text

/ /g
Flags
Examples
$1 … $9 numbered groups, $<name> named groups, $& whole match, $$ a literal dollar.
Matches
–

Highlighted text

Match table

#IndexMatchGroups

Replacement result


      

Cheat sheet

. \d \w \sAny char (not newline); digit; word char [A-Za-z0-9_]; whitespace. Capitals \D \W \S negate.
[abc] [^abc] [a-z]Character set; negated set; range.
^ $ \bStart and end of text (or line with m); word boundary.
* + ? {n} {n,} {n,m}0 or more; 1 or more; 0 or 1; exactly n; n or more; between n and m. Add ? for lazy.
(x) (?:x) (?<n>x)Capture group; non-capturing group; named group. \1 or \k<n> back-reference.
a|bAlternation: a or b.
(?=x) (?!x) (?<=x) (?<!x)Lookahead; negative lookahead; lookbehind; negative lookbehind.
\p{L} \p{N} \p{Emoji}Unicode property classes (need the u flag).
\. \* \( \\Escape a special character to match it literally.

About this tool

This regex tester runs a JavaScript regular expression against your sample text as you type and shows every match highlighted in place, a table of matches with their positions and numbered and named capture groups, and a live preview of a replacement string that can use $1, $2, and

How it works

The pattern and flags are compiled with the browser's native RegExp constructor, so behavior matches what JavaScript does in production, including Unicode handling under the u flag and lookbehind support. To list matches the tool always iterates with the global flag using exec in a loop, advancing one character after a zero-length match to avoid infinite loops, and stops after 5,000 matches. If you leave g unchecked only the first match is reported, as String.prototype.match would return. Replacement runs the actual String.prototype.replace or replaceAll with your pattern and replacement string, so $1,

Frequently asked questions

What do the flags mean?

g finds all matches instead of stopping at the first. i ignores case. m makes ^ and $ match at line breaks rather than only at the start and end of the text. s lets the dot match newline characters. u turns on full Unicode mode, needed for \p{...} classes and for treating emoji as single characters. y (sticky) matches only at the exact position where the previous match ended, which is rarely what you want in a tester.

Why does my pattern that works in Python or PCRE fail here?

JavaScript regex differs from PCRE and Python in a few places: there are no possessive quantifiers or atomic groups, no inline modifiers like (?i), no \A or \Z anchors (use ^ and $ without m), and named groups use (?<name>...) with \k<name> for back-references. Lookbehind (?<=...) is supported in all current browsers. Unicode property escapes such as \p{L} require the u flag.

How do I use capture groups in the replacement?

Refer to numbered groups as $1, $2, and so on, to named groups as

Is the match table limited?

Yes, to 5,000 matches, so a pattern that matches every character in a long text does not freeze the page. The count, highlighting, and replacement still cover the whole text; only the table stops at the cap and says so. If you need more, narrow the pattern or shorten the sample.

Related tools

JSON Formatter · Base64 Encode / Decode · URL Encode / Decode · Hash Generator · UUID Generator · JWT Decoder · HTML Entity Encoder · Color Converter · Password Generator · Number Base Converter · QR Code Generator · Chmod Calculator

Browse all Developer Tools, or go back to every free tool on HeroYears.