0
0
Google-sheetsHow-ToBeginner ยท 3 min read

How to Use REGEXREPLACE in Google Sheets: Simple Guide

Use REGEXREPLACE(text, regular_expression, replacement) in Google Sheets to replace parts of text that match a pattern with new text. It works by searching the text for matches to the regular_expression and replacing them with the replacement string.
๐Ÿ“

Syntax

The REGEXREPLACE function has three parts:

  • text: The original text or cell reference where you want to replace text.
  • regular_expression: The pattern you want to find, written as a regular expression.
  • replacement: The text you want to use instead of the matched pattern.

The function looks like this:

plaintext
REGEXREPLACE(text, regular_expression, replacement)
๐Ÿ’ป

Example

This example replaces all digits in the text with the word "#".

If cell A1 contains: Order123, the formula:

google_sheets_formula
=REGEXREPLACE(A1, "\\d", "#")
Output
Order###
โš ๏ธ

Common Pitfalls

Common mistakes include:

  • Not escaping special characters in the regular expression (like \).
  • Using plain text instead of a proper regular expression pattern.
  • Forgetting that the replacement text is literal and does not interpret regex groups unless you use $1, $2, etc.

Wrong example (missing escape for dot):

google_sheets_formula
=REGEXREPLACE("file.txt", ".txt", "_backup.txt")

Correct example (escaped dot):
=REGEXREPLACE("file.txt", "\.txt", "_backup.txt")
๐Ÿ“Š

Quick Reference

ParameterDescriptionExample
textText or cell to search"Hello123"
regular_expressionPattern to find"\\d" (matches digits)
replacementText to replace matches"#"
โœ…

Key Takeaways

REGEXREPLACE replaces text matching a pattern using regular expressions.
Always escape special regex characters like dot (.) with double backslashes (\\).
Replacement text is literal; use $1, $2 to refer to captured groups if needed.
Test your regex pattern to avoid unexpected replacements.
Use REGEXREPLACE to clean or format text dynamically in your sheets.