String.prototype.matchintermediate'test 123 foo'.match(/d+/) // β ['123', index: 5, ...]
'test 1 and 2'.match(/d+/g) // β ['1', '2']Use match() to search a string against a regex and return the match results, or null if not found.
Without the g flag, .match() returns an array where index 0 is the full match and index 1, 2, β¦ are capture groups.
Challenge: Implement parseDate(str) that extracts year, month, and day from 'YYYY-MM-DD' and returns them as numbers.
parseDate('2024-01-15') // β { year: 2024, month: 1, day: 15 }