Text Processingflags: g

Named Capture Group (Date)

Demonstrate named capture groups by extracting year/month/day from ISO-style dates.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})", "g");
const input = "Born 1990-05-21, hired 2018-09-10";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})   (flags: g)

Raw source: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

How it works

(?<year>\d{4}) captures four digits under the name 'year'; (?<month>\d{2}) and (?<day>\d{2}) likewise. Modern JS, Python 3.7+ (with Python's own `(?P<...>)` spelling — its stdlib `re` has never accepted the JS-style `(?<...>)` form), and Go (which accepts both `(?P<...>)` and, since Go 1.22, `(?<...>)`) all support named capture; the matched substring is accessible by name in code (e.g. m.groups.year in JS, m['year'] in Python).

Examples

Input

Born 1990-05-21, hired 2018-09-10

Matches

  • 1990-05-21
  • 2018-09-10

Input

Today is 2026-04-25

Matches

  • 2026-04-25

Input

no dates here

No match

Common use cases

  • Self-documenting regex in production code
  • Extracting structured fields from log lines
  • Form field validation with named outputs
  • Building parsers without positional bookkeeping

Related patterns