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.
str.match(regexp) returns an array with the match information when found, or null when not found.
Without the g flag, it returns the first match plus capture groups.
Challenge: Implement matchDigits(str) that returns the first sequence of digits in str using /\d+/.
matchDigits('abc123def') // β '123'
matchDigits('no digits') // β null