Skip to content

matchAll

The matchAll() method takes a regular expression as an argument and returns an iterator of all matches found in a string.

Interactive example

Syntax

Classic signature

typescript
function matchAll<
	GenericInput extends string
>(
	input: GenericInput, 
	pattern: RegExp
): RegExpStringIterator<RegExpMatchArray>;

Curried signature

typescript
function matchAll<
	GenericInput extends string
>(
	pattern: RegExp
): (input: GenericInput) => RegExpStringIterator<RegExpMatchArray>;

Parameters

  • input: The string to analyze.
  • pattern: The regular expression to use to find matches. It must have the g (global) flag to find all matches.

Return value

An iterator (RegExpStringIterator<RegExpMatchArray>) that lets you iterate over all matches found in the input string.

See also

  • match: Searches for a match with a regular expression.
  • search: Searches for a match with a regular expression.
  • indexOf: Returns the index of the first occurrence of a substring.
  • lastIndexOf: Returns the index of the last occurrence of a substring.

Sources

Released under the MIT license.