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.
| Input | Result | Matched |
|---|---|---|
| 2026-08-15 | matches | 2026-08-15 |
| on 1999-12-31 exactly | matches | 1999-12-31 |
| 2026/08/15 | no match | — |
| 26-08-15 | no 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 RegexBuilderOther regex answers
- Regex for an email address
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex for a date in YYYY-MM-DD format
- Regex to match digits only
- Regex for alphanumeric characters
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a UUID