Skip to content

replaceAll ​

The replaceAll() method returns a new string in which all occurrences of a specified pattern are replaced by a replacement string.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function replaceAll(
	input: string, 
	pattern: string | RegExp, 
	replacement: string
): string;

Curried signature ​

typescript
function replaceAll<
	GenericInput extends string
>(
	pattern: string | RegExp, 
	replacement: string
): (input: GenericInput) => string;

Parameters ​

  • input: The string in which to perform the replacements.
  • pattern: The pattern to search for. It can be a string or a regular expression.
  • replacement: The replacement string.

Return value ​

A new string with all occurrences of the pattern replaced by the replacement string.

See also ​

  • replace: Replaces the first occurrence of a pattern in a string.
  • includes: Checks whether a string contains a given pattern.
  • indexOf: Returns the index of the first occurrence of a pattern in a string.
  • toLowerCase: Converts the entire string to lowercase.

Sources ​

Released under the MIT license.