REGEXREPLACE Function
REGEXREPLACE searches text for a pattern and replaces matching parts with new text.
Syntax
Parameters
| Parameter | Description | Required |
|---|---|---|
| text | The original text or cell reference. | Required |
| regular_expression | The RE2 pattern to find in the text. | Required |
| replacement | The text to replace matches with. Use $1, $2, etc. to refer to capture groups. | Required |
Basic Example
Remove all digits from a product code
=REGEXREPLACE('ABC-123-XYZ', '\d', '')The pattern \d matches any digit. Replacing all digits with an empty string removes them.
Advanced Examples
Example 1: Reformat a phone number
Data cleaningConvert '(555) 123-4567' to '555-123-4567'
=REGEXREPLACE(A2, '\((\d{3})\)\s*(\d{3})-(\d{4})', '$1-$2-$3')Example 2: Remove extra whitespace
Text cleanupReplace multiple consecutive spaces with a single space
=REGEXREPLACE(A2, '\s+', ' ')How REGEXREPLACE Works
REGEXREPLACE scans the text for all matches of the pattern and replaces each match with the replacement string. The replacement can include references to capture groups using $1, $2, etc. It uses RE2 regex syntax.
Important Notes & Limitations
REGEXREPLACE is Google Sheets only. Excel has no built-in regex replacement function.
It uses RE2 syntax, which lacks some advanced regex features like lookahead/lookbehind.
Replacement is global; there is no built-in option to replace only the first match.
Special characters in the replacement string may need escaping.
Common Errors & Fixes
#VALUE! errorThe regular expression is invalid or uses unsupported syntax.Fix: Validate the regex and use RE2-compatible patterns.
Replacement not appliedThe pattern does not match the text.Fix: Test the pattern with REGEXMATCH first to ensure it matches.
$1 not replacedCapture groups are not defined or the replacement syntax is wrong.Fix: Use parentheses in the pattern and $1, $2 in the replacement string.
Download Practice File
REGEXREPLACE
regexreplacePractice REGEXREPLACE with Real Data
Download a sample CSV file with pre-populated data and practice exercises for the REGEXREPLACE function. Works in both Excel and Google Sheets.
File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps