JS Built-ins
StringString.prototype.matchadvanced

String.prototype.match() β€” named 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() β€” Named Groups

Named groups use (?<name>...) syntax and are accessible via result.groups.

Challenge: Implement parseColor(str) that extracts r, g, b from 'rgb(255,128,0)' using named groups.

parseColor('rgb(255,128,0)') // β†’ { r: 255, g: 128, b: 0 }
πŸ’‘ Hints (1)
  • β€’ Named groups are in `result.groups` (may be undefined if no groups matched).