jskatas.org Continuously Learn JavaScript. Your Way.

String API: string.matchAll()

Returns all results matching a regular expression.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

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)?"