1. Home
  2. Functions
  3. Text
  4. REGEXREPLACE

REGEXREPLACE function

Replaces the parts of a text that match a regular expression pattern.

Syntax

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

Arguments

ArgumentRequiredDescription
textRequiredThe text to change
patternRequiredThe regular expression
replacementRequiredThe replacement text ($1, $2 insert capture groups)
occurrenceOptional0 replaces all matches (default); n only the nth, negative counts from the end
case_sensitivityOptional0 match case (default), 1 ignore case

How to use REGEXREPLACE

REGEXREPLACE takes 3 required arguments and 2 optional arguments. Type =REGEXREPLACE( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=REGEXREPLACE("a1b22c333", "[0-9]+", "#")Result "a#b#c#"
=REGEXREPLACE("John Smith", "(\w+) (\w+)", "$2, $1")Result "Smith, John"
=REGEXREPLACE("a-b-c", "-", "+", 2)Result "a-b+c"

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.