JS Built-ins
StringString.prototype.matchintermediate

String.prototype.match() β€” capture groups

πŸ“– Usage Example
'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.

String.prototype.match() β€” Capture Groups

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 }
πŸ’‘ Hints (1)
  • β€’ Capture group values are at indices 1, 2, 3 in the result array.