Skip to content

match ​

The match() method searches for a match between a string and a regular expression, and returns the results as an array or undefined if no match is found.

WARNING

Deprecated. Use extract instead.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function match<
	GenericInput extends string
>(
	input: GenericInput, 
	pattern: string | RegExp
): RegExpMatchArray | undefined;

Curried signature ​

typescript
function match<
	GenericInput extends string
>(
	pattern: string | RegExp
): (input: GenericInput) => RegExpMatchArray | undefined;

Parameters ​

  • input: The string to search in.
  • pattern: The search pattern, which can be a string or a regular expression.

Return value ​

A match array (RegExpMatchArray) if one or more matches are found, or undefined if no match is found.

See also ​

  • 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.