Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

REGEXREPLACE in Google Sheets: Clean and Reformat Text with Patterns

REGEXREPLACE in Google Sheets
Illustration: REGEXREPLACE in Google Sheets

The REGEXREPLACE function in Google Sheets finds text that matches a pattern and replaces it. The syntax is =REGEXREPLACE(text, regular_expression, replacement). For example, =REGEXREPLACE(A2, "[0-9]", "") removes every digit from the text in A2. It is the right tool when SUBSTITUTE is too simple, such as when you need to clean phone numbers, strip extra characters or reformat text. This guide covers the syntax, common patterns, groups and the errors to expect. The sample data is made up.

Syntax

=REGEXREPLACE(text, regular_expression, replacement)

  • text is the text or cell to change.
  • regular_expression is the pattern to find, in quotes.
  • replacement is the text to put in its place. Use "" to delete.

Google Sheets uses RE2 regular expression syntax. REGEXREPLACE replaces all matches, not just the first. It is case sensitive unless you add the case insensitive flag (?i) at the start of the pattern.

REGEXREPLACE syntax in Google Sheets
Text, pattern, replacement (illustration).

Remove all digits

=REGEXREPLACE(A2, "[0-9]", "")

For "Room 12B" the result is "Room B". The pattern [0-9] matches any single digit, and an empty replacement removes it. You can write \d for a digit too, but in a Sheets formula check how the backslash behaves in your sheet and test it on one cell.

Keep only digits

Put a caret inside the brackets to match everything that is not a digit:

=REGEXREPLACE(A2, "[^0-9]", "")

For the phone number "(555) 010-0100" the result is "5550100100". The value is text, so wrap it in VALUE if you need a number.

Keep only digits in a phone number with REGEXREPLACE
Made-up phone numbers (illustration).

Remove extra spaces

=REGEXREPLACE(A2, " +", " ")

This replaces runs of spaces with a single space. TRIM does the same job more simply for normal spaces.

Remove punctuation

=REGEXREPLACE(A2, "[.,;:!?]", "")

Put the characters you want to remove between the brackets.

Make text case insensitive

=REGEXREPLACE(A2, "(?i)blue", "Navy")

This replaces "Blue", "BLUE" and "blue" alike.

Swap last and first name with REGEXREPLACE groups
$1 and $2 refer to groups (illustration).

Swap parts with groups

Brackets capture a part of the match, and $1, $2 refer to the captured parts in the replacement. To turn "Lee, Ann" into "Ann Lee":

=REGEXREPLACE(A2, "(.+), (.+)", "$2 $1")

The first group is the last name and the second is the first name, and the replacement puts them in the opposite order.

Replace only at the start or end

Use ^ for the start and $ for the end. To remove a trailing comma: =REGEXREPLACE(A2, ",$", ""). To remove leading zeros: =REGEXREPLACE(A2, "^0+", "").

Apply it to a whole column

Wrap it in ARRAYFORMULA: =ARRAYFORMULA(REGEXREPLACE(A2:A100, "[^0-9]", "")). Our ARRAYFORMULA examples show the pattern. Blank cells give blank results.

Common REGEXREPLACE patterns in Google Sheets
Start, end, spaces and case (illustration).

Related functions

To pull out a piece of text instead of replacing it, see REGEXEXTRACT. To split text by a separator, see the SPLIT function examples.

Common errors

  • Nothing changes. The pattern did not match, often because of case. Add (?i).
  • Invalid regular expression. A bracket or special character is not closed. Characters such as . ( ) [ ] + * ? need a backslash if you mean them literally.
  • A number is returned as text. The function always returns text. Wrap it in VALUE.
  • Lookaheads fail. RE2 does not support them. Use a simpler pattern.

Questions and answers

What is the difference between SUBSTITUTE and REGEXREPLACE?

SUBSTITUTE replaces fixed text. REGEXREPLACE replaces patterns, such as "any digit".

Does Excel have REGEXREPLACE?

Regular expression functions have only recently begun to appear in Excel, and availability depends on your version and update channel. Look in your function list. If you do not have it, use SUBSTITUTE, or Flash Fill for one off jobs.

Does it replace only the first match?

No. It replaces every match in the text.

How do I test a pattern first?

Try it on one cell with sample text, and change it step by step until the result is right.

العربية