A fully tested regex that extracts and validates date parts using named capturing groups.
Validations:
Capturing groups:
| # | Name | Description |
|:-:|:-------:|-------------------------------------|
| 1 | `year` | 4 digits of the year |
| 2 | `sep` | Date parts separator |
| 3 | `month` | 2 digits of the month |
| 4 | `day` | 2 digits of the date (day of month) |
Example usage:
let match = regex.exec('2020-11-22')
console.log('year: %s, month: %s, day: %s',
match.groups.year,
match.groups.month,
match.groups.day)
// year: 2020, month: 11, day: 22
Compatibility: (updated 2020-11-20)
See regex compatibility table.
Note: does not validate leap years (not really possible in regex)