Regex Tester for JavaScript Regular Expressions
By TheToolsBank Editorial TeamLast updated:
How to test a regex
- Type the pattern in the Pattern box without the slashes. Write
\d+, not/\d+/. - Tick the flags you need: Global (g), Case-insensitive (i), Multiline (m) or Dot-all (s).
- Paste your sample text into Test string.
- Select Test Regex. Results update when you select it again, not as you type.
Example: the pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) on Due 2026-10-31 and 2026-12-01 finds 2 matches. The list shows Match 1 at index 4: "2026-10-31" with groups ["2026","10","31"] plus named: {"year":"2026","month":"10","day":"31"}. The list shows the first 20 matches, then a line such as ...and 5 more (all are highlighted above). The tester stops after 1,000 matches and says so.
Regex cheat sheet
| Token | Meaning | Example |
|---|---|---|
. | Any character except a line break | a.c matches abc and a.c |
\d \w \s | Digit, word character (letter, digit, _), whitespace | \d+ finds 12 and 3 in "Order 12 shipped 3 items" |
\b | Word boundary | \bcat\b matches cat but not concat |
^ $ | Start and end of the text (of each line with m) | ^\w+ finds the first word |
[abc] [^abc] | One character from the set, or not in it | gr[ae]y matches gray and grey |
? * + {2,4} | 0 or 1, 0 or more, 1 or more, 2 to 4 times | colou?r matches color and colour |
+? *? | Lazy: match as little as possible | <.+?> finds <b> and </b> separately |
(...) (?:...) | Capture group, non-capturing group | (\w+)@(\w+)\.com captures ana and mail |
\1 | Back-reference to group 1 | \b(\w+)\s+\1\b finds "is is" |
(?=...) (?!...) | Lookahead, negative lookahead | \d{3}(?!\d) finds 234 in 1234 |
(?<=...) (?<!...) | Lookbehind, negative lookbehind | (?<=\$)\d+ finds 49 in $49 |
To match a special character literally, escape it with a backslash: \. \$ \( \?. Without the backslash, a.c also matches abc.
Ready-to-test patterns
Each pattern was checked against the sample shown. They are quick checks, not full validators.
| Use | Pattern | Matches in sample |
|---|---|---|
| Email (find in text) | [\w.+-]+@[\w-]+(?:\.[\w-]+)+ | ana.lee+news@mail.example.com |
| Email (whole field) | ^[^\s@]+@[^\s@]+\.[^\s@]+$ | ana@example.com, but not ana@example |
| US phone number | \(?\d{3}\)?[-.\s]?\d{3}[-.\s]\d{4} | (555) 123-4567, 555.123.4567, 555 123 4567 |
| US ZIP code | \b\d{5}(?:-\d{4})?\b | 90210 and 10001-1234, not 123456 |
| Date YYYY-MM-DD | \b\d{4}-\d{2}-\d{2}\b | 2026-10-31 |
| Hex color | #[0-9a-fA-F]{6}\b | #1E90FF, not #fff |
| URL | https?://\S+ | https://thetoolsbank.com/tool/regex-tester |
What the flags do here
- i ignores case.
\bcat\bwith i matches both cat and Cat. - m makes
^and$match at every line start and end. Without it,^\w+finds only the first word of the whole text. - s lets
.match line breaks too. - g is ticked by default and finds every match. Untick it to see only the first match, just as
execbehaves without g. In your own code, g also decides whetherreplacechanges one match or all of them.
JavaScript regex support and limits
Lookbehind, named groups and back-references all work. Possessive quantifiers like a++ and atomic groups like (?>...) are not part of JavaScript, so they show an error such as Nothing to repeat or Invalid group. The u flag is not offered, so \p{L} does not match letters here.
Each test runs in the background with a limit of about 2 seconds. If a pattern with nested quantifiers, like ^(a+)+$, runs longer, the tester stops it and shows Pattern took too long, so the tab does not freeze. There is no replace preview. To replace matches in text, use Find and Replace.
Common Mistakes to Avoid
Typing the pattern with slashes and flags, like /cat/i.
Solution:
Using ^ and $ on multi-line text without the m flag.
Solution:
Using a greedy .+ between quotes or tags.
Solution:
Forgetting to escape dots and dollar signs.
Solution:

