Regex Tester
Test JavaScript regular expressions with match counts, bounded highlights and capture groups. Cancellable browser Worker with a two-second limit.
- Runs in your browser
- Your data never leaves your browser
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Common Regex Patterns
\d+— one or more digits\w+— one or more word characters (letters, digits, underscore)[a-zA-Z]+— letters only^\s+|\s+$— leading or trailing whitespace(\w+)@(\w+.\w+)— simple email capturehttps?://\S+— URLs
Tested Patterns
Each row shows what the tester returns with the g flag on:
| Pattern | Test string | Matches |
|---|---|---|
<.+> | <a>foo</a> | <a>foo</a> (greedy: first < to last >) |
<.+?> | <a>foo</a> | <a>, </a> (lazy) |
-?\d+(?:\.\d+)? | temp -3.5, max 42 | -3.5, 42 |
#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\b | #fff #1a73e8 #12345g | #fff, #1a73e8 |
(?<=\$)\d+ | cost $42 | 42 (lookbehind) |
^(?<ts>\S+)\s+(?<level>\w+)\s+(?<msg>.+)$ | 2026-04-07T14:23:01 ERROR connection refused | 1 match; groups 2026-04-07T14:23:01, ERROR, connection refused |
A regex checks the format only. ^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$ accepts 2026-02-31, so parse dates with a date library.
Flags in Practice
The same text gives different results as flags change. With this three-line log as the test string:
ERROR disk full
WARN retry 3
ERROR timeout
^ERROR .+with onlygfinds 1 match (ERROR disk fullat index 0):^means the start of the whole text.- Add
mand it finds 2 matches, the second at index 29, because^now matches after every line break. The index counts the two newline characters too. .never crosses a line break unlesssis on:a.bfinds nothing in “a”, newline, “b” until you ticks.cafewithionCafé CAFE cafefindsCAFEandcafebut notCafé; case-insensitive matching does not ignore accents.
Each match line shows its index, and each capture group is listed under it in order, including groups that did not take part in the match (shown as undefined). There is no Run button: the result updates 0.3 seconds after you stop typing. To try a pattern against a JSON document instead, the JSONPath tester queries by path rather than by text.
Common Mistakes
- Unescaped metacharacters.
.*+?()[]{}^$|\have special meanings. Write\.to match a dot. ^and$in multi-line text. Without themflag they match only at the start and end of the whole text.\wis ASCII only.\w+oncafé 東京matches onlycaf. Use a character range such as[\u4e00-\u9fff]+for Chinese characters.- Nested quantifiers.
(a+)+$can take a long time on a near-match. Matching runs in a native JavaScript RegExp Worker with a two-second total limit. Cancel stops it immediately. A timeout or cancellation gives no complete result. Changing the input stops the previous run.
Limits
- JavaScript syntax only. Python’s
(?P<name>...)gives “Invalid group”; use(?<name>...). Patterns written for Go (RE2), PCRE, or .NET can behave differently. - Four flags. Only
g,i,m, andsare available. There is nouflag, so\p{L}is read as the literal textp{L}, andy,d, andvare not available. - Groups are listed by number. Named groups appear as Group 1, Group 2, and so on.
- Full counts, bounded preview. Completed runs count every match. Highlights cover the first 100,000 UTF-16 units and at most 1,000 matches. The list shows the first 100 matches and 20 groups per match; each value is limited to 1,000 units, with a total value budget of 100,000 units. Shortened values end in
…. Indices use UTF-16 units, so an emoji before a match adds 2. Worker support is required. - No replace. The tester finds matches; it does not run
replace().
FAQ
Which regex flavor does this tool use?
JavaScript (ECMAScript) regex via the browser's built-in RegExp engine.
What flags are supported?
g (global), i (case-insensitive), m (multiline), and s (dotAll — dot matches newline). You can combine them.
Why does 'g' flag matter?
Without 'g', only the first match is returned. With 'g', all matches are found.
Are capture groups shown?
Yes. The list shows the first 100 matches and up to 20 groups per match. Shortened values are marked with … .