Flowfiles ← Regex Tester

Regex Named Capture Groups

Test (?<name>…) patterns · Extract labeled values · Replace with $<name> — free, no signup

Named capture groups let you label parts of a regex pattern and retrieve them by name instead of index. Test them live with our online regex tester — group values appear labeled in the match panel.

Test named capture groups right now — paste your pattern and see each group extracted by name.

Open the Regex Tester →

Named groups syntax and examples

A named capture group uses (?<name>…). The name must start with a letter and contain only letters, digits, or underscores. You can have multiple named groups in the same pattern.

// Extract date parts
const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const m = '2024-03-15'.match(re);
console.log(m.groups.year); // "2024"
console.log(m.groups.month); // "03"
console.log(m.groups.day); // "15"

In Replace mode, use $<name> to reference the group:

'2024-03-15'.replace(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/, '$<d>/$<m>/$<y>')
// → "15/03/2024"

With the g flag, iterate with matchAll():

const text = 'foo@a.com bar@b.org';
const re = /(?<user>[\w.]+)@(?<domain>[\w.]+)/g;
for (const m of text.matchAll(re)) {
  console.log(m.groups.user, m.groups.domain);
}

Frequently asked questions

What is a named capture group?

A named capture group assigns a label to a capturing group using (?<name>…). Values are accessible via match.groups.name instead of by index. This makes patterns more readable and refactoring safer.

Are named groups available in all browsers?

Yes. Named capture groups were introduced in ES2018 and are supported in all modern browsers (Chrome 64+, Firefox 78+, Safari 11.1+, Edge 79+).

Can two groups share the same name?

In ECMAScript 2025+, duplicate named groups are allowed in alternations ((?<x>a)|(?<x>b)). In older engines this throws a SyntaxError, so avoid duplicates for broad compatibility.

How do I use named groups with replaceAll?

String.prototype.replaceAll() with a regex requires the g flag. The replacement string syntax is the same: $<name>. You can also pass a function as the second argument and access match.groups in it.

Related tools