JS Built-ins
StringString.prototype.matchAllintermediate

String.prototype.matchAll() β€” access capture groups

πŸ“– Usage Example
const str = 'a1 b2 c3'
const matches = [...str.matchAll(/(w)(d)/g)]
matches.length   // β†’ 3
matches[0][1]    // β†’ 'a'

Use matchAll() with the g flag to iterate over all regex matches and access capture groups in each result.

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

Each match result in matchAll is a full match object with capture groups at indices 1, 2, etc.

Challenge: Implement extractNumbers(str) that returns all digit sequences as numbers.

extractNumbers('price: 42 and 100') // β†’ [42, 100]
πŸ’‘ Hints (1)
  • β€’ Each match result `m` has `m[1]` for the first capture group.