Trace a named capture from a regex to a match report
Admin ·
The pattern tree describes how a match is constructed. The result list shows where the browser actually found one in the supplied text.
Read two capture groups
Enter (?<code>[A-Z]{2})-(\d+) with flags dg and test text AB-123 and CD-45. The tree shows a named capture containing a repeated letter range, a literal hyphen and a second capture containing repeated digits. The first complete match spans positions 0 to 6. Its code capture spans 0 to 2 and contains AB.
Remove g and run the same example. The report contains only the first match. With g restored, the second match spans 11 to 16.
MDN JavaScript guide to groups and backreferencesECMAScript regular expression patterns
Inspect a zero-length match
Use the empty pattern with gu and the single character 😀 as the test text. The report has two empty matches, at offsets 0 and 2. Unicode matching advances over the full code point when moving to the next empty match. The preview marks each empty match with ∅.
Make a list of near misses as well as matches
For a two-letter region code followed by a dash and digits, test AB-12 alongside A-12, AB- and XAB-12. An unanchored pattern can find a substring inside the last example. If the entire field must match, use start and end anchors and repeat the test with the same flags.
Check the matched span, not just whether a result exists. When validating a list of separate lines, verify the effect of the multiline flag on those anchors.
Common questions
What changes when I add the d flag?
The report gains an indices array. Its first entry spans the complete match. The remaining entries follow the numbered captures, with null for a group that did not participate.
Why does a run stop at the time limit?
Some patterns require many matching attempts for the supplied text. The page terminates the worker after three seconds. Edit the pattern or use a shorter sample to inspect it again.