How does your regular expression match, step by step?
Test a JavaScript regular expression on your text, see every match and group, and read the pattern in plain words.
What you enter stays on your device while you use this tool. Opening a shared link sends the settings in its address to HowToolbox to prepare the page.
A JavaScript regular expression, without the slashes.
Presets and flags
Flags
Result
2 matches
Matches
| No. | Match | Position |
|---|---|---|
| 1 | 2026-11-07 | 22 |
| 2 | 2027-01-15 | 37 |
Groups
| No. | Group | Value |
|---|---|---|
| 1 | 1 | 2026 |
| 1 | 2 | 11 |
| 1 | 3 | 07 |
| 2 | 1 | 2027 |
| 2 | 2 | 01 |
| 2 | 3 | 15 |
What the pattern means
| Part | Meaning |
|---|---|
| (…) | capture group 1 |
| \d{4} | a digit from 0 to 9, exactly 4 times |
| - | the text “-” |
| (…) | capture group 2 |
| \d{2} | a digit from 0 to 9, exactly 2 times |
| - | the text “-” |
| (…) | capture group 3 |
| \d{2} | a digit from 0 to 9, exactly 2 times |
JavaScript flavour: the browser's own regular expression engine does the matching, so results are what your JavaScript code would get.
Patterns that could backtrack catastrophically are not run, and slow-prone patterns limit the text length.
Test a JavaScript regular expression on your text, see every match and group, and read the pattern in plain words.
How to use
- Type your pattern without the slashes, and switch on the flags you need. The g flag finds every match instead of the first.
- Paste the text to test. Each match is marked in the text and listed with its position and capture groups.
- Read the explanation to see what each part of the pattern does, from the outside in.
How it works
A regular expression is a pattern that describes text. Letters match themselves, \d stands for a digit, a dot for almost any character, and brackets list the characters allowed in one place. Quantifiers say how many times to repeat the part before them: a star for any number, a plus for at least one, a question mark for optional. Round brackets group parts and capture what they matched.
The browser's own regular expression engine does the matching, so the result is what JavaScript gives you. The engine tries the pattern from each position and backs up when a choice fails. Quantifiers are greedy and take as much as they can, unless a question mark after them makes them lazy. Some patterns, such as a repeated group that itself contains a repeat, make the engine try an enormous number of ways on certain texts: that is catastrophic backtracking, and it can freeze a page.
To keep the page responsive, patterns of that kind are recognised and not run, and patterns that can be slow limit how long the text may be. The check recognises the known risky shapes; it cannot prove every other pattern safe. Other languages have their own flavours, so lookbehind, named groups and Unicode escapes may behave differently outside JavaScript.
Worked example
What does (\d+)-(\d+) match?
- \d+ is one or more digits, and the round brackets capture them as a group.
- The hyphen is an ordinary character that must follow the first group.
- A second group of digits follows the hyphen.
It matches two numbers joined by a hyphen, such as 2026-11 or 40-2, and captures each number separately.
Sources
- Ecma International: ECMAScript Language Specification, RegExp objectsUsed for: definitions
- OWASP: Regular expression Denial of Service (ReDoS)Used for: limits and cut-offs
Frequently asked questions
What does the g flag do?
It finds every match in the text instead of stopping at the first one.
What is the difference between greedy and lazy?
A greedy quantifier takes as much text as it can, a lazy one (with a question mark after it) as little as it can. Against a tag in angle brackets, .* takes up to the last closing bracket and .*? stops at the first.
How do I match a literal dot or bracket?
Put a backslash before it, for example \. for a dot. Inside square brackets most of these characters are already literal.
Why was my pattern not run?
It has a shape that can backtrack catastrophically, such as a repeat inside a repeat. Rewrite it so each part can match in only one way, for example (a+)+ becomes a+.
Does it use the same engine as my code?
Yes, for JavaScript and TypeScript. For other languages the common syntax is the same, but details such as lookbehind and flags can differ.





