Check Sheet Logo
Check Sheet

REGEXREPLACE

The REGEXREPLACE formula is used to replace a piece of text that matches a regular expression with a new piece of text. This formula is useful when working with text data that needs to be cleaned or manipulated based on specific patterns or rules.

Usage

Use the REGEXREPLACE formula with the syntax shown below, it has 3 required parameters:

=REGEXREPLACE(text, regular_expression, replacement)
Parameters:
  1. text (required):
    The text string that you want to search for a matching pattern.
  2. regular_expression (required):
    The regular expression that defines the pattern you want to replace in the text string. Note that the syntax for regular expressions in Google Sheets is the same as in JavaScript.
  3. replacement (required):
    The replacement text that you want to use for any matches found by the regular expression. You can include capture groups from the regular expression in this parameter using the $ notation.

Examples

Here are a few example use cases that explain how to use the REGEXREPLACE formula in Google Sheets.

Removing special characters from data

You can use the REGEXREPLACE formula to remove special characters, such as parentheses or hyphens, from data in a spreadsheet. This can be useful when cleaning and standardizing data from different sources.

Extracting numbers from text

If you have a text string that contains numbers, you can use the REGEXREPLACE formula to extract only the numbers from the string. This can be useful when working with data that needs to be analyzed or sorted numerically.

Replacing specific words or phrases

You can use the REGEXREPLACE formula to replace specific words or phrases in a text string. This can be useful when working with data that needs to be updated or corrected based on specific criteria.

Common Mistakes

REGEXREPLACE not working? Here are some common mistakes people make when using the REGEXREPLACE Google Sheets Formula:

Using incorrect regular expression syntax

One common mistake when using REGEXREPLACE is using incorrect syntax when defining the regular expression pattern. This can cause the formula to not work as intended or return errors. It is important to review and test the regular expression pattern to ensure it is correct before using it in the formula.

Not escaping special characters in the regular expression pattern

When using special characters in the regular expression pattern, such as parentheses or brackets, it is important to escape them using backslashes. Failure to do so can cause errors or unexpected results.

The following functions are similar to REGEXREPLACE or are often used with it in a formula:

  • REGEXMATCH

    The REGEXMATCH formula searches for a regular expression pattern within a specified text string, and returns a boolean value of TRUE if the pattern is found, and FALSE if it is not found. This formula is commonly used to check if a string matches a certain pattern or to extract specific information from a text string based on a pattern.

  • REGEXEXTRACT

    The REGEXEXTRACT formula is used to extract a portion of a text string that matches a regular expression. This is useful when you need to extract specific information from a text string that follows a certain pattern.

  • SUBSTITUTE

    The SUBSTITUTE formula is used to replace specific text in a string with new text. It is commonly used to replace all occurrences of a certain word or character within a larger string. The formula has the option to specify which occurrence to replace, or it will replace all occurrences by default.

  • LOWER

    The LOWER formula converts all letters in a specified text string to lowercase. It takes one required parameter, which is the text string to be converted. This formula is commonly used to standardize text data for easier analysis and comparison.

  • UPPER

    The UPPER formula in Google Sheets converts all the letters in a given text string to uppercase. It takes one required argument, the text to convert. This formula is commonly used to standardize text data or to make it easier to compare text values.

Learn More

You can learn more about the REGEXREPLACE Google Sheets function on Google Support.