How to Test a Regex Online (JavaScript Regex Tester Guide)

To test a regex online, type the pattern (without slashes) into the Toolstik Regex Tester, tick the flags you need, such as Global (g) or Ignore case (i), paste sample text into Test text, and click Test regex. Matches are highlighted in place, counted, and listed in a table with their index and capture groups. The tester uses your browser's JavaScript regex engine, and your text never leaves the page.
Try it now
Regex Tester
Loading tool…
Step by step
- Open the Regex Tester. It loads with an email-style pattern and a short sample, so you can see the output before changing anything.
- Type your pattern in Pattern. Leave out the surrounding slashes: the tool shows
/before the field and/plus the active flags after it. - Set Flags with the checkboxes:
- Global (g): find every match, not just the first.
- Ignore case (i):
cafealso matchesCafeandCAFE. - Multiline (m):
^and$match at each line break, not just the start and end of the text. - Dot matches newline (s):
.also matches\n. - Unicode (u): treat surrogate pairs such as emoji as one character, enable
\p{...}property escapes, and apply stricter syntax checks.
- Paste up to 100,000 characters into Test text.
- Click Test regex or press Enter in the pattern field. The button reads "Testing…" while it runs.
Reading the results
- Match count appears first: "No matches", "1 match", or "N matches". The tool collects up to 1,000 matches. Beyond that, the count shows a
+(for example "1000+ matches"). - Highlighted text shows every match marked in place, which is the fastest way to spot a match that's too wide or too narrow.
- Match table lists
#,Index(zero-based character offset),Match, andGroups. Numbered groups appear as$1: value, and named groups asname: value. An empty match is shown as "(empty)". The table lists the first 100 matches.
Try it with the built-in sample. The default pattern is:
[\w.+-]+@[\w-]+(?:\.[\w-]+)+
It finds sales@toolstik.com and support@example.org and skips hello@ and @nowhere.com. Now change the ending to the looser [\w-]+\.[\w.]+ and test again: the second match becomes support@example.org., including the sentence's final period, because [\w.]+ happily eats dots. This "match looks right until you see the highlight" moment is exactly what a tester is for.
Useful patterns to start from
\d{3}-\d{4}matches 555-1234 style numbers.(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})matches ISO dates and captures named groups.\b\d{1,2}:\d{2}\bmatches times like 9:05 and 10:30.(?<=\$)\d+matches the digits after a dollar sign (lookbehind).^\s+|\s+$matches leading or trailing whitespace on each line (turn on g and m).
Against Order 2026-10-10 shipped 2026-10-12 with Global (g) on, the date pattern gives two rows. Named groups are numbered too, so the first row's Groups column reads $1: 2026 · $2: 10 · $3: 10 · year: 2026 · month: 10 · day: 10.
Moving a tested pattern into code
The tester takes the pattern exactly as you'd write it in a JavaScript regex literal. When you move it into a string, backslashes must be doubled:
const literal = /\d{3}-\d{4}/g;
const fromString = new RegExp("\\d{3}-\\d{4}", "g"); // same regex
"call 555-1234".match(literal); // ["555-1234"]
The same applies to JSON config files, where \d must be written \\d, otherwise you get an invalid escape error (see common JSON errors). If the pattern lives in a URL query parameter, percent-encode it with the URL Encoder / Decoder.
Troubleshooting
Greedy vs lazy
Quantifiers like * and + are greedy: they match as much as possible, then back off.
"<b>one</b> and <b>two</b>".match(/<b>.*<\/b>/)[0];
// "<b>one</b> and <b>two</b>" (one big match)
"<b>one</b> and <b>two</b>".match(/<b>.*?<\/b>/g);
// ["<b>one</b>", "<b>two</b>"] (lazy: two matches)
Add ? after a quantifier to make it lazy, or better, use a negated class like [^<]* that can't run past the boundary.
Forgetting to escape
. matches any character, so \d+.\d+.\d+ matches 1x2y3 as well as 1.2.3. Escape the metacharacters you mean literally: . * + ? ( ) [ ] { } ^ $ | \ and /. Use \., \$, \+, and so on.
Only one match
Global (g) is off. Without it, the tester stops after the first match, just as "a1 b2".match(/[a-z]\d/) returns only a1.
Catastrophic backtracking
Nested quantifiers can make the engine try an exponential number of paths when a match fails. ^(a+)+$ against 29 a characters followed by ! took about 30 seconds in Node.js in our test. Toolstik runs matching in a background Web Worker and stops it after 2 seconds with a message suggesting you make quantifiers more specific. Fixes:
- Remove the nesting:
^a+$does the same job instantly. - Make alternatives mutually exclusive, so
(a|aa)+can't split the same text two ways. - Anchor the pattern and use specific classes (
[^,]*instead of.*).
PCRE, Python, or other flavor syntax
Patterns copied from PHP, Perl, or Python docs may not work in JavaScript:
| Syntax | Works in | In JavaScript |
|---|---|---|
a++, a*+ (possessive) | PCRE, Java | Error: "Nothing to repeat" |
(?>...) (atomic group) | PCRE, Java, .NET | Error: invalid group |
(?P<name>...) | Python, PCRE | Error. Use (?<name>...). |
(?i) at the start | PCRE, Python | Error. Use the Ignore case (i) flag. |
\A, \Z | PCRE, Python | Without u, \A silently matches a literal A. Use ^ and $. |
[[:alpha:]] | POSIX, PCRE | Silently wrong. Use [a-zA-Z] or \p{L} with u. |
Recursion (?R) | PCRE | Not supported |
Newer JavaScript engines also accept scoped modifiers like (?i:abc), but support depends on your browser version.
Related tools
Cleaning up text before matching? The Case & Slug Converter normalizes case. Regexes are handy for pulling fields out of logs, too: pretty-print a JSON log line with the JSON Formatter first, or turn an epoch value you've extracted into a date with the guide on how to convert a Unix timestamp. The full toolkit is in free developer tools online.
Frequently asked questions
Tools in this guide
Regex Tester
Test JavaScript regular expressions with live match highlighting, capture groups, and flags.
JSON Formatter & Validator
Format, validate, and minify JSON. Tree view with syntax error highlighting.
URL Encoder / Decoder
Encode or decode URLs and query components with encodeURI or encodeURIComponent.
Case & Slug Converter
Convert text to Title Case, sentence case, camelCase, snake_case, kebab-case, or a clean URL slug.
Keep reading
- DeveloperCommon JSON Errors and How to Fix ThemFix common JSON errors fast: trailing commas, single quotes, unquoted keys, comments, BOMs, NaN, and raw line breaks, with before-and-after examples.
- DeveloperHow to Convert a Unix Timestamp to a Date (and Back)How to convert a Unix timestamp to a readable date and back: seconds vs milliseconds, time zones, the 2038 problem, and copy-ready code for JS, Python, SQL, and bash.
- DeveloperFree Developer Tools Online: JSON, JWT, Base64, URL, Timestamp & RegexFree developer tools online that run in your browser: format JSON, decode JWTs, encode Base64 and URLs, convert Unix timestamps, and test JavaScript regex.