REPLACE

Replaces all occurrences of a specified search string with a replacement string

Description

The REPLACE() function is used to replace all occurrences of a specified search string with a replacement string within a given text. It's a versatile tool for text manipulation and data cleaning.

Syntax

REPLACE(text, search, replace)

  1. text: The input text string in which you want to perform replacements.

  2. search: The text you want to find and replace.

  3. replace: The text with which you want to replace the found search string.

The REPLACE() function is case-sensitive, meaning it will only replace text that exactly matches the specified search string in terms of both character sequence and letter case. If you need case-insensitive replacement, you may consider using REGEX_REPLACE() to achieve the desired result.

Example

Table

ID
Text

1

Huge SALE on electronics today!

2

Special SALE: Save 20% on select items.

3

No SALE available for this product.

Function

REPLACE(`Text`, "SALE", "DISCOUNT")

Results

REPLACE (text)

Huge DISCOUNT on electronics today!

Special DISCOUNT: Save 20% on select items.

No DISCOUNT available for this product.

Last updated