Formula
new RegExp(pattern, flags) applied with matchAll / exec
- Matches are reported with their position in the text.
- Zero-length matches are counted but not highlighted.
The tool runs the same regular-expression engine that JavaScript uses.
Worked example
Two numbers around a dash
- Pattern
- (\d+)-(\d+)
- Flags
- g
- Test text
- a 10-20 b 3-4
Matches
2
Flags used: g
Capture groups: 2
How it works
The pattern is compiled with the browser's own RegExp engine and run over your text. Each match is listed with its start position and the value of every capture group, numbered or named, and matches are highlighted in the text. Add a replacement to preview the result of String.replace, where $1 refers to the first group.
Regular-expression syntax differs between languages: lookbehind, named groups and Unicode property escapes work here as in modern JavaScript, but Python, PCRE and Java have their own differences. Patterns with nested repetition (such as (a+)+) can be very slow on some inputs because of backtracking, and a pathological pattern can freeze this tab, so inputs are capped at 100,000 characters and 1,000 matches. See also Word Counter and Case Converter for simpler text tasks, or the JSON Validator for data checks.
Assumptions and limits
- JavaScript (ECMAScript) syntax only.
- No timeout is applied, so extremely complex patterns can make the page unresponsive until you reload it.