No need to escape the dashes btw:
$ node
> '02-14-1924'.match(/\d{2}-\d{2}-\d{4}/)
[ '02-14-1924', index: 0, input: '02-14-1924', groups: undefined ]That's poor usage of regex. Try this:
$ node
> let XRegExp = require('xregexp');
> XRegExp.exec('02-14-1924', XRegExp(`
(?<day> \\d{2} ) -
(?<mon> \\d{2} ) -
(?<year> \\d{4} )
`, 'x'))
[ '02-14-19',
'02',
'14',
'1924',
index: 0,
input: '02-14-1924',
groups: undefined,
day: '02',
mon: '14',
year: '1924' ]
If a (dynamically built) regex misbehaves, I'm only inspecting the lines of code that compose the string, not an entire library to understand what went wrong.