About the JavaScript Regex Tester
This is a JavaScript-specific regex tester. You write a pattern the way you would inside `new RegExp(pattern, flags)` or a `/pattern/flags` literal, set the flags you need, run it against sample text, and see every match highlighted live with its capture groups broken out.
Because the underlying engine is literally the browser's own RegExp implementation, not a reimplementation or approximation, whether a given pattern matches given text here agrees with what your JavaScript code will do, since both use the same ECMAScript RegExp semantics. One thing this tester does differently: it always scans for every match internally, similar to `matchAll`, so the match count and highlighting stay accurate whether or not you type the g flag yourself; a single `String.prototype.match` or `RegExp.prototype.exec` call in your own code still needs g to return more than the first match.
Use it to work out validation patterns, log-parsing expressions, URL and route matchers, or search-and-replace patterns before wiring them into code, and to sanity-check a flag combination (g plus i plus m, for instance) actually behaves the way you expect against real sample text rather than in your head.
Everything runs client-side. The pattern and test string never leave your browser, which matters if your test text includes real emails, tokens or other data you would rather not paste into a server-side tool.
How to use it
- Enter your pattern in the pattern field exactly as it would appear inside new RegExp(...) or between the slashes of a /pattern/ literal.
- Set flags: g for global, i for case-insensitive, m for multiline, s for dotAll, u for unicode, y for sticky, d for match indices.
- Paste the sample text you want to run the pattern against.
- Review the live match count, the highlighted matches in the text, and each match's numbered or named capture groups.
- Toggle flags on and off to confirm which one changes the outcome, rather than guessing from documentation.
- Adjust the pattern until it matches everything it should and nothing it should not, including edge cases in your sample text.
- Drop the confirmed pattern and flag string straight into your JS or TS code.
Examples
- Pattern (\d{2})/(\d{2})/(\d{4}) with flag g against "29/07/2026 and 01/01/2027" returns two matches, each exposing day, month and year as numbered groups 1, 2 and 3.
- Pattern ^\s*$ with flag m against a multi-line string matches every blank line individually, because m makes ^ and $ line-relative instead of string-relative.
- text.replace(/(\w+)\s(\w+)/, "$2 $1") style backreferences: testing (\w+)\s(\w+) against "John Smith" shows group 1 as John and group 2 as Smith, which is what $1 and $2 would resolve to in a .replace() call.
- Pattern /foo/y (sticky) only matches foo starting exactly at lastIndex, unlike the same pattern without y, which will scan forward through the string to find foo anywhere.
- Pattern \p{Script=Greek}+ with flag u against "Hello Ελλάδα" matches Ελλάδα, since Unicode property escapes like \p{Script=...} require the u (or v) flag to be recognized at all.
- Testing the same /pattern/g literal twice in a row against different strings can appear to skip matches in real code because a global regex is stateful and remembers lastIndex between calls; the tester avoids that trap by re-running matchAll fresh each time you edit.
RegExp flags reference
JavaScript regex flags change how the engine matches without changing the pattern text itself. Some are everyday tools, some solve a specific, narrow problem, and it is worth knowing all of them exist even if you rarely reach for the rarer ones.
- g (global): find all matches instead of stopping after the first one
- i (ignoreCase): match letters regardless of case
- m (multiline): ^ and $ match the start and end of each line, not just the whole string
- s (dotAll): . Also matches line-terminator characters like \n
- u (unicode): treats the pattern as a sequence of Unicode code points and enables \p{...} property escapes
- v (unicodeSets): a newer, stricter superset of u with better support for set operations inside character classes
- y (sticky): only matches starting exactly at lastIndex, does not scan forward to find a match further in the string
- d (hasIndices): also returns the start and end index of each capture group, not just of the whole match
Lookbehind support and browser compatibility
Lookbehind, (?<=...) and (?<!...), landed in JavaScript with ECMAScript 2018. Engines based on V8 (Chrome, Edge, Node) supported it early; Safari lagged noticeably and only added it in Safari 16.4, released in 2023. If your code has to run in older Safari or in a WebView tied to an older engine, a pattern that works perfectly here in a modern browser can still throw a SyntaxError at parse time in that environment, since unsupported lookbehind is not just a mismatch, it fails to compile the RegExp at all. When targeting older runtimes, either feature-detect support before constructing the RegExp, or restructure the pattern to avoid lookbehind (for instance by capturing the preceding context and discarding it in code, rather than asserting it inline).
Common JavaScript regex mistakes
A few mistakes come up disproportionately often in JavaScript specifically, mostly because of how the RegExp object carries state.
- Reusing a global (g) or sticky (y) regex literal across multiple .test() or .exec() calls: lastIndex persists on the object between calls, so the second call can silently start partway through the string instead of at the beginning
- Building a RegExp from a variable with new RegExp(str) without escaping user-controlled characters in str, which lets characters like . Or ( change the meaning of the pattern instead of being matched literally
- Confusing .replace(pattern, "$1") string replacement syntax (which uses $1, $2 for numbered groups and $<name> for named ones) with .replace(pattern, (match, g1) => ...) callback syntax, which instead receives each group as its own function argument
- Assuming . Matches absolutely any character; without the s flag it does not match line terminators, which silently breaks patterns tested only against single-line sample text
Frequently asked questions
What is a JavaScript regex tester?
It is a regex tester built specifically around JavaScript's RegExp object and ECMAScript regex syntax, so patterns, flags and match behavior are guaranteed to line up with what your JS or TypeScript code will actually do.
Is this the same as testing regex in the browser console?
Functionally yes: both use the same underlying RegExp engine. This page adds live highlighting, a match count and a breakdown of capture groups on top, so you do not have to manually call matchAll and log the result yourself.
Does this JavaScript regex tester run online or in my browser?
The page loads once from a server, but the pattern and test text you type are matched entirely inside your browser's own JavaScript engine. Nothing you test is sent anywhere.
How do I test a regex in JavaScript for a specific flag combination?
Type the flags you want to test, such as gi or gm, directly into the flags field next to the pattern. The match count and highlighted output update immediately so you can see exactly what each flag changes.
Why does my JavaScript regex only match once even with the global flag?
This usually means the g flag was left off, or a stateful lastIndex from a previous .exec() call on the same RegExp object caused matching to resume from the wrong position. A fresh matchAll() call, which this tester uses internally, avoids the lastIndex issue.
Does this support JavaScript named capture groups?
Yes. Groups written as (?<name>...) are recognized and listed by name alongside their matched text, the same as accessing match.groups.name in your own code.
Can I test sticky (y) and unicode (u) flags here?
Yes, both are supported since they are native JavaScript RegExp flags. Sticky matching only succeeds starting at the current position rather than scanning ahead, which is easiest to see by comparing the same pattern with and without y.
Is a JavaScript regex tester different from a generic online regex tester?
A generic tester may target PCRE or another server-side flavor by default. This one is explicitly JavaScript-only, which matters for details like named group syntax, lookbehind support and flag semantics that differ between flavors.