Home โบ Regex Tester (JavaScript)
Regex Tester (JavaScript)
How to use this regex tester
Type a pattern between the slashes and flags after the closing slash. The test string is matched live with the browser's own RegExp engine, so what you see is exactly what str.match(), matchAll() and replace() will do in Node.js, Deno, Bun and every modern browser. Each match is highlighted, and the table lists its position, numbered groups and named groups.
Flags
| Flag | Name | Effect |
|---|---|---|
g | global | Find all matches instead of the first one. |
i | ignoreCase | Case-insensitive matching. |
m | multiline | ^ and $ match at every line start/end, not only the whole string. |
s | dotAll | . also matches newlines. |
u | unicode | Treat the pattern as Unicode code points; enables \p{โฆ}. Recommended for any non-ASCII text. |
y | sticky | Match only at lastIndex; used in tokenizers. |
Cheat sheet
| Token | Matches |
|---|---|
\d \w \s | digit, word character [A-Za-z0-9_], whitespace (uppercase = negation) |
[abc] [^abc] [a-z] | character set, negated set, range |
* + ? {2,5} | 0+, 1+, 0 or 1, between 2 and 5 times (add ? for lazy: *?) |
^ $ \b | start, end, word boundary |
(โฆ) (?:โฆ) (?<name>โฆ) | capturing, non-capturing, named group |
(?=โฆ) (?!โฆ) (?<=โฆ) (?<!โฆ) | lookahead, negative lookahead, lookbehind, negative lookbehind |
\1 \k<name> | back-reference to a group |
Practical patterns
ISO date ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Hex color ^#(?:[0-9a-fA-F]{3}){1,2}$
IPv4 (strict) ^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$
Trailing spaces [ \t]+$ (with the m flag)
Semantic version ^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$
Validating email addresses with a regex is a classic trap: the sample pattern above is deliberately simple. For real sign-up forms, check for an @, then send a confirmation email.
Frequently asked questions
Why does my regex only find the first match?
Without the g (global) flag, JavaScript's match and replace stop after the first match. Add the g flag. This tester always lists all matches, but the replacement preview respects your flags exactly like String.prototype.replace does.
How do I make the dot match newlines?
Add the s (dotAll) flag. Without it, . matches any character except line terminators. The older workaround is [\s\S], which works in every engine.
Is JavaScript regex the same as PCRE, Python or Java regex?
Mostly, but not entirely. JavaScript supports lookbehind, named groups (?<name>...) and Unicode property escapes \p{L} with the u flag, but it has no possessive quantifiers, no atomic groups and no recursion, and inline modifiers such as (?i:...) only exist in the newest engines. Test in the same engine you deploy to.
Why does the page freeze with some patterns?
Patterns with nested quantifiers such as (a+)+$ can cause catastrophic backtracking: the engine tries an exponential number of paths on input that almost matches. This is the cause of many ReDoS vulnerabilities. Rewrite the pattern so that each character can be matched in only one way.