Toolbox-XToolbox-X

Replace All in String

Replaces all occurrences of a specified substring or pattern in an input string.

replaceAllInString

The replaceAllInString function replaces all occurrences of a specified substring or RegExp pattern in a given input string.

Function Signature

function replaceAllInString(input: string, find: string | RegExp, replace: string): string

Parameters

  • input (string): The input string to perform replacements in.
  • find (string | RegExp): The substring or pattern to search for. If a string is passed, it is converted to a global RegExp. If a RegExp is passed, the global (g) flag is verified and added if missing.
  • replace (string): The replacement string.

Return Value

  • string: The modified string with all occurrences replaced.

Example Usage

playground.ts

Notes

  • The function trims leading and trailing whitespace from the input string before executing the replacement.

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page