Skip to main content

Replacing Text in Strings

AMPS provides a pair of functions, REPLACE and REGEXP_REPLACE, that replace text within strings.

REPLACE

REPLACE


REPLACE(string_to_transform, string_to_match, replacement_text)

Returns the input string, with all occurrences of the string_to_match replaced with the replacement_text. This function does a literal match of the string to be replaced.

Parameters

  • string_to_transform: The string to transform.
  • string_to_match: The string to search for.
  • replacement_text: The text to replace the matched string with.

Returns

The transformed string.

REGEXP_REPLACE

REGEXP_REPLACE


REGEXP_REPLACE(string_to_transform, pattern_to_match, replacement_text)

Returns the input string, with all occurrences of the pattern_to_match replaced with the replacement_text. This function uses a PCRE pattern to find the string to be replaced.

Parameters

  • string_to_transform: The string to transform.
  • pattern_to_match: The PCRE pattern to search for.
  • replacement_text: The text to replace the matched string with.

Returns

The transformed string.