JS Built-ins
StringString.prototype.matchAllintermediate

String.prototype.matchAll() β€” match index property

πŸ“– 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() β€” Match Index

Each match result has an index property indicating where the match starts.

Challenge: Implement matchIndices(str, ch) that returns an array of indices where ch occurs.

matchIndices('abacaba', 'a') // β†’ [0, 2, 4, 6]
πŸ’‘ Hints (1)
  • β€’ Each match result `m` has a numeric `m.index` property.