Regex Tester
Run a JavaScript regular expression against sample text with your own flags, list every match or capture group, and start from common patterns.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the Regex Tester?
The Regex Tester runs a regular expression against sample text and lists what it finds. It uses JavaScript's own RegExp engine, so a pattern that works here behaves the same way in browser code, Node.js, Deno and most TypeScript projects.
You type the pattern, set flags such as g, i or m in the Flags box, paste your test text and click Test Regex. With the g flag you get every match; without it you get the first match followed by its capture groups, which is how String.prototype.match behaves. Matches can be copied out as a newline-separated list.
Six starter patterns (Email, Phone (US), URL, IP Address, Date (MM/DD/YYYY) and Hex Color) fill the pattern box with one click. Treat them as starting points: they are deliberately simple and accept some strings a strict validator would reject.
- Native JavaScript RegExp engine, the same one your front-end code uses
- Free-form flags field (g, i, m, s, u, y)
- Capture groups listed when the g flag is off
- Six one-click starter patterns
- Match list with one-click copy; runs entirely in your browser
Updated
How to use the Regex Tester
- Enter your pattern in the Regex Pattern field without surrounding slashes, for example \b\d{3}-\d{4}\b, or click one of the common patterns.
- Set flags in the Flags box. The default is g, which finds all matches. Add i for case-insensitive or m for multiline anchors.
- Paste the text you want to search into Test Text.
- Click Test Regex to see whether it matched and the list of matches, then copy them if needed.
Worked examples
All four-digit order numbers
Input
Pattern \b\d{4}\b, flags g, text "Order 4521 shipped, order 4522 pending"Output
4521, 4522
The \b word boundaries stop the pattern from matching four digits inside a longer number such as 452199.
Capture groups without the g flag
Input
Pattern (\d{4})-(\d{2})-(\d{2}), flags empty, text "2026-10-24"Output
2026-10-24, 2026, 10, 24
Without g the list shows the whole match first, then each group in order. Add g and you get only whole matches, which is often why groups seem to disappear.
Background and insight
Regular expressions come from formal language theory. The mathematician Stephen Kleene described "regular events" in the 1950s, and Ken Thompson brought the idea into practical computing in the late 1960s with the QED editor and later ed and grep. Perl in the late 1980s added much of the syntax developers now treat as standard, such as \d, \w, lazy quantifiers and lookahead.
Every language ships its own flavour. JavaScript's is close to Perl's but not identical: lookbehind arrived only in ES2018, named groups use (?<name>...) syntax, and there is no possessive quantifier or atomic group. That is why it pays to test in the same engine your code will use, rather than a generic tester set to PCRE.
The most common real-world regex bug is not a typo, it is a pattern that is too permissive. A pattern like .* happily matches across the thing you meant to stop at. Testing against both text that should match and text that should not is the habit that catches this.
Common use cases
Validating input formats
Check a pattern for postcodes, order numbers or internal IDs against real samples before shipping a form validator.
Extracting data from logs
Pull request IDs, IP addresses or error codes out of a pasted log excerpt.
Preparing search and replace
Confirm a pattern matches exactly what you expect before running it across a codebase in your editor.
Learning regex
Experiment with quantifiers, character classes and anchors and see the effect immediately.
Tips and limitations
- Escape backslashes when you copy a pattern into a JavaScript string: \d here becomes "\\d" inside new RegExp("...") but stays \d inside a /.../ literal.
- The IP Address preset matches 999.999.999.999 too. Validating ranges such as 0 to 255 is easier in code than in a regex.
- Anchor validators with ^ and $. Without them, a "valid email" pattern also matches inside "not an email: a@b.co!!!".
- Nested quantifiers like (a+)+ can take exponential time on inputs that almost match. If a test hangs the tab, that is catastrophic backtracking.
- Add the u flag when your text contains emoji or other characters outside the Basic Multilingual Plane, so . and character classes treat them as one character.
Sources and further reading
- Regular expressions, MDN Web Docs. The JavaScript flavour this tester uses, with flags and syntax
- ECMA-262: ECMAScript Language Specification, Ecma International. The standard that defines JavaScript RegExp
- Representation of Events in Nerve Nets and Finite Automata, RAND Corporation. Kleene's 1951 memorandum on regular events
- Regular Expression Matching Can Be Simple And Fast, Russ Cox. Thompson's construction and the history of regex engines
Frequently asked questions
Which regex flavour does this tester use?
JavaScript (ECMAScript), through the browser's built-in RegExp. Lookbehind, named groups and the s (dotAll) flag work in current browsers. PCRE-only features such as possessive quantifiers, atomic groups and recursion do not, so test patterns for PHP or Python in their own engines.
Do I include the slashes around the regex pattern?
No. Enter just the pattern, for example ^\w+$, and put flags in the separate Flags box. If you paste /abc/i including the slashes, they become part of the pattern and the tester will look for literal slash characters in your text.
Why does my pattern only find one match?
Without the g flag, JavaScript returns only the first match, plus its capture groups. Keep g in the Flags box to list every match in the text. In your own code, use matchAll with a g flag when you need every match together with its groups.
Why does . not match a newline in JavaScript regex?
By default the dot matches any character except line terminators such as \n and \r. Add the s (dotAll) flag to make it match newlines too, or use [\s\S] in code that must run on engines older than ES2018.
Is the test text I paste into the regex tester uploaded?
No. Matching runs locally in your browser with JavaScript, and neither the pattern nor the text is sent anywhere. You can paste log excerpts that contain internal hostnames or IDs, although redacting secrets is still a good habit.
How do I make a regex case-insensitive?
Add i to the Flags box, so the flags read gi. In code that is /pattern/gi or new RegExp(pattern, "gi"). JavaScript does not support inline modifiers such as (?i) in most runtimes, so the flag is the reliable way to do it.
Is there an in-depth guide to the Regex Tester?
Yes. “Regular Expressions in JavaScript: A Field Guide for Working Developers” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
Related Tools You May Like
Free, in-browser tools that pair well with this one.