Skip to main content

REGEXREPLACE

Replaces text matching a regular expression with new text.

Syntax​

REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])

Arguments​

  • text: The text or reference to a cell containing the text to modify.
  • pattern: The regular expression to match against.
  • replacement: The replacement text. Reference capture groups from pattern as \1, \2, and so on.
  • occurrence: [Optional] 0 or omitted replaces every match. A positive number N replaces only the Nth match, leaving the rest of the text untouched.
  • case_sensitivity: [Optional] TRUE (default) matches case-sensitively. Pass FALSE for a case-insensitive match.

Example​

REGEXREPLACE("apple banana apple", "apple", "orange") → Returns "orange banana orange"
REGEXREPLACE("apple banana apple", "apple", "orange", 2) → Returns "apple banana orange"
REGEXREPLACE("2026-09-16", "(\d+)-(\d+)-(\d+)", "\3/\2/\1") → Returns "16/09/2026"
REGEXREPLACE("Apple apple", "apple", "orange", 0, FALSE) → Returns "orange orange"

A common use is normalizing a value before matching on it elsewhere, such as a claim number that may arrive with mixed case, punctuation, or a leading zero:

REGEXREPLACE(REGEXREPLACE(LOWER({{Claim Number}}), "[-. ]", ""), "^0", "")

The inner call lowercases the value and strips dashes, dots, and spaces; the outer call drops exactly one leading zero if present, without touching the rest of the digits.

Usage Notes:

  • Returns text unchanged for an invalid pattern instead of erroring out the formula.
  • Regular expressions are JavaScript-flavored (ECMAScript), which covers the vast majority of common patterns but is not identical to Excel's PCRE2 flavor for advanced features like some POSIX character classes.
  • See REGEXTEST to just check for a match, and REGEXEXTRACT to pull the matching text out without replacing it.