How to test a JavaScript regular expression
This regex tester runs your pattern against sample text as you type and highlights every match in place, each in its own colour. Below the editor it lists each match with its position and the value of every capture group, so you can see exactly what your pattern captured — not just whether it matched.
Patterns run on your browser's own JavaScript RegExp engine, so behaviour matches what you'll get in Chrome, Firefox, Safari, Node.js, Deno or Bun. Nothing you type is sent anywhere.
How to use the regex tester
- Type a pattern between the slashes — without the surrounding
/characters, just as you'd write the inside of a regex literal. - Toggle flags:
g(find all matches),i(ignore case),m(^and$match at each line),s(.matches newlines). - Paste or type test text. Matches are highlighted immediately; invalid patterns show the engine's error message.
- Read the match list for each match's index and its capture groups, and use the quick reference panel when you forget a token.
Example: extract dates from a log line with named groups.
Pattern: (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})
Flags: g
Text: deployed 2026-10-09, rolled back 2026-10-10
Match 1: "2026-10-09" at 9 groups: 2026, 10, 09
Match 2: "2026-10-10" at 33 groups: 2026, 10, 10Regex syntax at a glance
| Token | Meaning | Token | Meaning |
|---|---|---|---|
\d | Digit | * | 0 or more |
\w | Letter, digit or _ | + | 1 or more |
\s | Whitespace | ? | Optional |
. | Any char except newline | {2,5} | 2 to 5 times |
[a-z] | Character range | *? | Lazy (as few as possible) |
^ $ | Start / end | (…) | Capture group |
\b | Word boundary | (?:…) | Group without capturing |
a|b | a or b | (?=…) | Lookahead |
The full reference — named groups, backreferences, lookbehind, Unicode property escapes and the u, y, d and v flags — is in the JavaScript regex cheatsheet.
Why doesn't my regex match?
- Unescaped special characters.
.matches any character; to match a literal dot write\.. The same applies to? * + ( ) [ ] { } ^ $ | \ /. - Anchors without
m.^and$match only at the start and end of the whole text unless themflag is on. Testing line by line? Turn onm. - Only one match. Without the
gflag, JavaScript stops at the first match. - Greedy quantifiers.
".*"on"a" and "b"matches the whole string"a" and "b". Use the lazy".*?"or a negated class"[^"]*". - Newlines.
.does not match line breaks unless you enables. Windows text may also contain\rbefore each\n. - Copying from code. Inside a string passed to
new RegExp("…"), backslashes are doubled ("\\d+"). Paste the pattern as it would appear in a/…/literal instead.
Performance and safety
Patterns with nested quantifiers such as (a+)+ or (\w+\s*)* can backtrack exponentially on input that almost matches, hanging a browser tab or a server. This is known as ReDoS (regular-expression denial of service). If the tester becomes slow on a long input, simplify the pattern: avoid quantified groups that can match the same text in several ways, and prefer specific character classes over .*.
Regex flavours differ. A pattern tested here behaves the same in any JavaScript runtime, but PCRE (PHP), Python's re, Go's RE2 and Java each have small differences — RE2, for example, has no backreferences or lookarounds. Re-test when moving a pattern between languages.
Frequently asked questions
Which regex flavour does this tester use?
JavaScript (ECMAScript). The pattern is compiled with your browser's native RegExp, so results match Chrome, Firefox, Safari and Node.js.
Do I include the slashes and flags in the pattern?
No. Enter only the pattern body, and toggle flags with the buttons. For /\d+/gi type \d+ and enable g and i.
How do I see capture groups?
Each match in the results list shows its numbered capture groups. Named groups like (?<year>\d{4}) are captured too and appear in order.
Is my test text uploaded?
No. Matching runs locally in your browser. Recent patterns are saved only in your browser's history panel, which you can clear.