Tools/Developer Tools/Regex Tester

Regex Tester – Test JavaScript Regular Expressions

Test JavaScript regular expressions against your own text. Every match is highlighted, with its index and capture groups listed below.

If this tool isn’t working as expected, please take a screenshot of the error and report the problem here so we can investigate and improve it.

About this tool

This regular expression tester runs your pattern against your own text with the browser's JavaScript RegExp engine and highlights every match, with each match's index and its capture groups listed underneath. The g, i, m and s flags are toggles.

The search always scans the whole text and stops collecting after 500 matches. The pattern and text stay in your browser.

Because this is the engine your JavaScript, TypeScript and Node.js code uses, a match here is a match there. If the pattern is meant for another language, the first FAQ explains what can differ.

How to Use Regex Tester

Enter Pattern

Type your regex pattern and select the flags you need.

Paste Test Text

Add the string you want to test the pattern against.

See Matches

Matching text is highlighted and match details appear below.

Review Groups

Check match count, index positions, and capture groups.

Common Workflows

Checking a form validation pattern

Paste valid and invalid samples, one per line, and see which ones match before the pattern goes into a validator. Turn on m if the pattern is anchored with ^ and $.

Finding out why a pattern matches too much

The highlighted view shows exactly how far each match runs. If a greedy quantifier swallows more than you meant, try its lazy form; the first example below compares the two.

Extracting values with capture groups

Pull dates, IDs or other fields out of log lines and read each group's value for every match.

Testing against a decoded log line

Decode a percent-encoded or Base64 string with the Text Encoder first, then test the pattern against the readable text.

Examples

Greedy vs lazy quantifiers change what matches

Pattern & Test Text

Pattern: <.+> (greedy) · Test text: <a><b>

Matches

Match 1: <a><b> (index 0) - a single greedy match.

Switching to <.+?> (lazy) instead finds:
Match 1: <a> (index 0)
Match 2: <b> (index 3)

Greedy quantifiers (+, *, {n,}) match as much text as possible; lazy ones (+?, *?) as little as possible.

Capture groups in Match Details

Pattern & Test Text

Pattern: (?<year>\d{4})-(?<month>\d{2})-(\d{2}) · Test text: 2026-07-12

Match Details

Match 1: 2026-07-12 (index 0)
Group 1 (year): 2026
Group 2 (month): 07
Group 3: 12

Groups are numbered in the order their opening parentheses appear. A named group shows its name next to its number; an unnamed one is just the number.

The DotAll flag lets . cross a line break

Pattern & Flags

Pattern: a.b · Test text: "a" + newline + "b"

Result

Without the s flag: "No matches found for this pattern in the test text."
With the s flag enabled: Match 1: a\nb (index 0)

By default . doesn't match a line break. The s flag makes it match \n too.

Common Mistakes

Problem

Using ^ and $ on several lines without the m flag

Solution

Without m, ^ and $ match only the start and end of the whole text, so ^\d+$ finds nothing in a text of several numbered lines. Turn on m to anchor each line.

Problem

Forgetting to escape a literal dot

Solution

An unescaped . matches any character, so the pattern 192.168.1.1 also matches 192x168y1z1. Write \. to match a real dot.

Problem

Expecting the tester's always-global search to match your code

Solution

The tool scans the whole text even with g switched off. In your own code, a pattern without g finds only the first match.

Limitations

Only the g, i, m and s flags

There are no toggles for u (Unicode), y (sticky), d (indices) or v (unicodeSets), although the engine supports them.

JavaScript only

There's no Python, PHP, Java, Go or PCRE mode. The tool always runs JavaScript's RegExp.

Matches, not replacements

It doesn't preview String.replace() or String.split() results with your pattern.

Capped at 500 matches

If the pattern matches more than 500 times, collection stops at the 500th match and the page says so.

Quick Reference

JavaScript regex syntax at a glance

The parts most patterns are built from. Every example runs as written in the tester above.

SyntaxMatchesExample
abcThe literal characters, case-sensitive unless the i flag is oncat finds "cat" in "concatenate"
.Any one character except a line break (also a line break with the s flag)a.c finds "abc" and "a-c"
\d \w \sA digit; a letter, digit or underscore; a whitespace character\d\d finds "42" in "order 42"
[abc] [^abc] [a-f]One character from the set; one character not in it; one in the range[aeiou] finds each vowel
* + ?Zero or more; one or more; zero or one of the item before itcolou?r finds "color" and "colour"
{n} {n,m}Exactly n repeats; between n and m repeats\d{3}-\d{4} finds "555-0199"
+? *?The lazy form: as few repeats as possible<.+?> finds "<a>" and "<b>" in "<a><b>"
^ $ \bStart and end of the text (of each line with the m flag); a word boundary\bcat\b finds "cat" but not "concatenate"
(...) (?:...)A capture group; a group that doesn't capture(\d+)-(\d+) captures both numbers
(?<name>...)A named capture group, shown by name in Match Details(?<year>\d{4}) names the year
a|bEither alternativecat|dog finds "cat" or "dog"
(?=...) (?!...)Lookahead: followed by, or not followed by, without including it in the match\d+(?= USD) finds "20" in "20 USD"
g i m sFlags: all matches (always on in this tester), ignore case, ^ and $ per line, . matches line breaksTurn on i and cat also finds "Cat"

FAQs

These cover why a pattern can behave differently here than in another language, which JavaScript features work, and how groups are shown.

Why does my regex work in another tester but not in JavaScript?

Some popular testers, regex101 among them, offer other flavors such as PCRE, and PCRE has features JavaScript lacks - atomic groups and possessive quantifiers, for example - while flavors also differ in group syntax. This tester runs the actual JavaScript RegExp engine, so a match here is a match in your JavaScript, TypeScript or Node.js code. If the pattern is meant for another language, treat a match here as a hint, not proof.

Can I test a regex for Python, PHP, Java or Go here?

Not with those languages' engines: the tester only runs JavaScript's RegExp. Simple patterns often behave the same everywhere, but details differ - Python writes a named group as (?P<name>...) where JavaScript writes (?<name>...), for example - so test in the target language before relying on a pattern.

How are capture groups and named groups shown?

Each match card lists its groups in the order of their opening parentheses: Group 1, Group 2 and so on. A named group, written (?<name>...), shows its name next to its number. A group that took no part in the match shows as undefined.

Which JavaScript regex features work here?

Whatever your browser's engine supports: lookahead, lookbehind in current browsers, named groups and backreferences all work. Unicode property escapes such as \p{L} need the u flag, which this tester has no toggle for, so without it \p{L} is read as the literal text p{L}.

Get more tools like this

Leave your email so we can prioritize similar tools and updates.