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
| Parameter | Description | Example |
|---|---|---|
| text | Text or cell to search | "Hello123" |
| regular_expression | Pattern to find | "\\d" (matches digits) |
| replacement | Text 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.