Replaces part of a text string with a different text string using regular expressions. Learn more
In Google Sheets, the REGEXREPLACE function is used to replace text in a cell based on a specified regular expression pattern.
Its syntax is as follows:
REGEXREPLACE(text, regular_expression, replacement)
text refers to the cell or text string where you want to perform the replacement.
regular_expression is the pattern you want to match in the text. It can be a string or a cell reference that contains the regular expression.
replacement specifies the text that will replace the matched pattern in the text. It can be a string or a cell reference containing the replacement text.
Here's an example to illustrate the usage of REGEXREPLACE in Google Sheets. Let's say we have the following data in cells A1:A3:
A1: "Hello, world!" A2: "OpenAI is awesome." A3: "Regular expressions are powerful."
If we want to remove all instances of vowels from the text in column A, we can use the REGEXREPLACE function with the regular expression [aeiou]. In cell B1, we would enter the following formula:
=REGEXREPLACE(A1, "[aeiou]", "")
This formula will replace any vowel (a, e, i, o, u) in the text in cell A1 with an empty string. By dragging the formula down to cells B2 and B3, we can apply the same logic to the other cells.
The resulting values in column B would be:
B1: "Hll, wrld!" B2: "OpnAI s wsm." B3: "Rglr xprssns r pwrfl."
As you can see, the REGEXREPLACE function allows you to manipulate text using regular expressions, providing a flexible way to perform text replacements in Google Sheets.