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.
With the g flag, .match() returns an array of all matched strings (no capture group details).
Challenge: Implement allWords(str) that returns all word tokens using /\w+/g.
allWords('hello world foo') // β ['hello', 'world', 'foo']