# REGEXREPLACE in Google Sheets: syntax and examples

URL: https://goingstellar.ro/reference/sheets/regexreplace/

REGEXREPLACE finds every part of a text that matches a RE2 pattern and replaces it. Use it to strip characters, reformat codes and dates, or clean input that SUBSTITUTE cannot describe.

Try the pattern first in our [RE2 regex tester](https://goingstellar.ro/tools/re2-regex-tester/): it uses RE2 syntax, the same as Google Sheets, and runs in your browser.

## Syntax

```
REGEXREPLACE(text, regular_expression, replacement)
```

## Arguments

- `text` (string, required: yes): The text to change.
- `regular_expression` (string, required: yes): A RE2 pattern. Every match is replaced.
- `replacement` (string, required: yes): The text that takes the place of each match. Numbered capture groups can be inserted.

## Examples

The examples use this table, starting in A1:

| Text |
|---|
| Tel: 0721 234 567 |
| ana.pop@example.com |
| too    many   spaces |
| Ana Pop |

```
=REGEXREPLACE(A2, "\D", "")
```

Result: `0721234567`

Keep only the digits: every non-digit character is replaced by nothing. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=REGEXREPLACE(A3, "@.*$", "")
```

Result: `ana.pop`

Remove everything from the @ onward, leaving the user name. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=REGEXREPLACE(A4, "\s+", " ")
```

Result: `too many spaces`

Collapse any run of whitespace into one space. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=REGEXREPLACE(A5, "(\w+) (\w+)", "$2, $1")
```

Result: `Pop, Ana`

Swap two words with capture groups: the first group goes after the second. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=ARRAYFORMULA(REGEXREPLACE(A2:A3, "[aeiou]", "*"))
```

Result: 

| T*l: 0721 234 567 |
|---|
| *n*.p*p@*x*mpl*.c*m |

Replace vowels in a whole range at once. Run in a Google Sheet (English US locale) on 2026-11-29.

## Common errors

- It replaces every match, not just the first. REGEXREPLACE("abab", "a", "x") gives xbxb.
- Matching is case sensitive. Start the pattern with (?i) to ignore case.
- An invalid pattern, such as an unclosed parenthesis, returns #REF!.
- The result is always text. A number passed in comes back as text.

## Compared with Excel

Older Excel versions have no REGEXREPLACE. The regex functions added to Microsoft 365 use a different pattern flavour, so test patterns before copying them.

## Related functions

- [REGEXEXTRACT](https://goingstellar.ro/reference/sheets/regexextract/)
- [REGEXMATCH](https://goingstellar.ro/reference/sheets/regexmatch/)
- [SUBSTITUTE](https://goingstellar.ro/reference/sheets/substitute/)
- [REPLACE](https://goingstellar.ro/reference/sheets/replace/)
- [TRIM](https://goingstellar.ro/reference/sheets/trim/)
- [VALUE](https://goingstellar.ro/reference/sheets/value/)

## Sources

- [REGEXREPLACE (Docs Editors Help)](https://support.google.com/docs/answer/3098245)

