Regex Named Capture Groups – Use (?<name>...) in JavaScript

Local only

Label captured substrings with JavaScript named groups so Match All output is easier to read and reuse.

12 chars · 1 line

5 chars · 1 line

Pattern matched the inputFlags: g

Regex named groups

How to use named capture groups in JavaScript regex

Named groups use (?<name>...) so a capture can be identified by purpose instead of only by position. The matcher displays JavaScript's named groups object next to the normal numbered captures. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Named capture inspection
  • Numbered captures
  • Named groups object
  • Match indexes
  • JavaScript RegExp semantics
  • Browser-local processing

Steps

  1. Replace an ordinary capturing group with (?<name>...) using a descriptive JavaScript group name.
  2. Run Match All and inspect the groups object in each result.
  3. Keep names unique within the pattern and verify optional groups against inputs where they may not participate.

Named groups still participate in normal capture numbering

A named group is still a capturing group. JavaScript exposes it both in the numbered capture sequence and by name, which can make downstream extraction and replacement logic easier to understand.

Named capture example

first and last label the two captured name parts.

Pattern and input

(?<first>[A-Za-z]+) (?<last>[A-Za-z]+)
Ada Lovelace

Named groups

first: Ada
last: Lovelace

Common questions

Frequently asked questions

Do named groups replace numbered groups?

No. Named captures are also available in the normal numbered capture sequence.

Can two groups use the same name?

JavaScript generally requires group names to be valid and unambiguous; duplicate names may be rejected depending on pattern structure and runtime support.

Can named groups be used in replacement strings?

Yes. JavaScript supports named-group replacement syntax when the pattern defines named captures.

Debugging a specific Regex issue? Browse Regex troubleshooting.