How this calculator works
- Step 1Compile the patternJavaScript RegExpThe same engine your browser and Node.js use.
- Step 2Search in the backgroundTime limitSlow patterns are stopped instead of freezing the page.
- Step 3Show and explainHighlightsEvery match, every group, and what each token means.
A regular expression is a small pattern language for finding text. Different languages share most of the syntax, but details such as lookbehind and named groups vary.
Worked example: an Indian mobile number
\b[6-9]\d{9}\b finds 2 numbers in the sample text: 9876543210 and 7012345678.
- Pattern
\b[6-9]\d{9}\b
- \ba word boundary
- [6-9]one character from [6-9]
- \d{9}a digit 0–9, exactly 9 times
- \ba word boundary
- Matches in the sample9876543210 at 5, 7012345678 at 33
“1234567890” is skipped because it starts with 1. The pattern checks only the shape of a number, not whether the number is in use.
Reading the result
- Without gFirst match onlyThe search stops after the first match.
- With gEvery matchThe search continues to the end of the text.
- HighlightsMatched text is marked and underlined in place.
- GroupsNumbered and named groups for each match.
- ExplanationA plain-English meaning for each token.
- Time limitPatterns that run too long are stopped with a message.
Related text tools
A regular expression finds patterns. Other tools clean, compare and reshape text.
To compare two texts line by line, use the diff checker. The remove duplicate lines tool tidies lists, and the case converter changes text to camelCase, snake_case and more.
Common mistakes
Mistake: Forgetting to escape a dot in a domain or price.
Instead: Write \. to match a real full stop.
Mistake: Nesting repeats such as (a+)+.
Instead: Make each repeat specific; nested repeats can take exponential time.
Mistake: Using a regex to fully validate email or dates.
Instead: Use it for shape, then check the value in code.
Mistake: Leaving out ^ and $ when the whole input must match.
Instead: Anchor the pattern, or a match inside longer text counts.
Read how we test our calculators, or browse more developer tools.