RRegexBuilder
Get RegexBuilder

RegexBuilder · regex answers

Regex with a named capture group

/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/

Named groups turn match[1] into match.groups.year, which survives someone inserting a group in front of it. Supported in JavaScript since 2018, in Python as (?P<name>...), and in .NET and PCRE with the same syntax as JavaScript.

What each part does

(?<year> … )a group captured under the name year
\d{4}its contents — four digits
-the literal separator between parts

Tested against real input

Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.

InputResultMatched
2026-08-15matches2026-08-15
on 1999-12-31 exactlymatches1999-12-31
2026/08/15no match
26-08-15no match

The mistake to avoid

Using (?<name>...) in Python, where the syntax is (?P<name>...). The pattern raises an error rather than silently misbehaving, which at least tells you quickly.

Try it on your own text

Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.

Open RegexBuilder

Other regex answers