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
- Tool input is not uploaded to ZeroTool servers
- 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.
With g and m ticked, the status line and the match list read:
2 matches found.
Match 1: ERROR disk full (index 0)
Match 2: ERROR timeout (index 29)
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.
Indexes, Emoji and Named Groups
The tool reports positions the way JavaScript counts them: in UTF-16 code units. An emoji outside the Basic Multilingual Plane takes two units, so a digit after 😀 sits at index 3, not 2. A named group is listed by its number:
1 match found.
Match 1: 7 (index 3)
Group 1: 7
Because there is no u flag, . also matches one code unit. ^.$ against the single character 😀 therefore finds nothing: the emoji is two units long.
No matches.
An invalid pattern shows a reason in the page language. For example, Python's named-group syntax gives:
Invalid regex: Invalid group syntax or unbalanced parentheses.
The page translates known V8, Firefox and Safari diagnostics. An unrecognized diagnostic shows a general syntax message in the page language; it does not display the original browser message. The Worker still uses the browser's native JavaScript syntax.
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 syntax or unbalanced parentheses."; use(?<name>...). Patterns written for Go (RE2), PCRE, or .NET can behave differently; the regex cheat sheet runs the same patterns in JavaScript, Python, PCRE2 and Go. - 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. It runs in a browser Worker that stops after two seconds.
What flags are supported?
g (global), i (case-insensitive), m (multiline), and s (dotAll — dot matches newline). You can combine them. There is no u, y, d or v flag.
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, numbered even when the group has a name. Shortened values are marked with … .
Is my pattern or test text sent anywhere?
No. Your browser runs the match in a Worker on this page; the pattern and the text are not sent to a server, and the tool does not write them to browser storage. The page loads Google Analytics, which receives the tool name and one 'match' event per page after the first committed run that finds a match: leaving an edited field or changing a flag. Opening the page, typing alone, errors, runs with no matches and canceled runs send no match event. The pattern and text are not included.
Can I paste a pattern written for Python or PCRE?
Only if it uses syntax that JavaScript shares. Python's (?P<name>...) gives 'Invalid group', and possessive quantifiers such as a++ and atomic groups (?>...) are errors in JavaScript. The same pattern can also match different text: Python's \d and \w accept Unicode digits and letters, JavaScript's only ASCII. The regex cheat sheet compares the engines.