The function string.matchAll()
searches for a string in another string
can also search using a regexp
also searches using a regexp
the regexp MUST use the global flag /g
finds any number of occurrences
finds all matches, of all capture groups
returns an iterator
the iterator has a key Symbol.iterator
the result can be looped over using for-of
Links
The repository where the proposal was worked on, some interesting details in there about naming and the process of how this became a standard.
The "ECMAScript Language Specification", the JavaScript specification text describing this function.
The Mozilla Developer Network docs, contains good examples.
"Why does the new "matchAll" in Javascript return an iterator (vs. an array)?"
Announcement of this kata on twitter.
Required Knowledge
- `const` declaration (Block scope)
- with arrays (Spread operator)
- `Array.from()` (Array API)
- array (Iterator)
Related Katas
Template strings
String API
string.includes()
string.repeat(count)
string.startsWith()
string.endsWith()
String.raw
string.trimStart()
string.matchAll()
Difficulty Level
ADVANCED
First Published
12 March 2022
Stats
7 tests to solve