The REGEXREPLACE function allows you to replace text from a string with another string, based on a supplied regular expression (“regex”).
Syntax
The REGEXREPLACE function replaces strings within the provided text that matches the pattern with replacement.
The syntax of the REGEXEXTRACT function is:
REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])
Argument | Description |
---|---|
text (required) | The text or the reference to a cell containing the text you want to replace strings within. |
pattern (required) | The regular expression (“regex”) that describes the pattern of text you want to replace. |
replacement (required) | The text you want to replace instances of pattern. |
occurrence | Specifies which instance of the pattern you want to replace. By default, occurrence is 0, which replaces all instances. A negative number replaces that instance, searching from the end. |
case_sensitivity | Determines whether the match is case-sensitive. By default, the match is case-sensitive. Enter one of the following: 0: Case sensitive 1: Case insensitive |
Notes: When writing regex patterns, symbols called ‘tokens’ can be used that match with a variety of characters. These are some simple tokens for reference:
“[0-9]”: any numerical digit
“[a-z]”: a character in the range of a to z
“.”: any character
“a”: the “a” character
“a*”: zero or more “a”
“a+”: one or more “a”
All regular expressions for this function, as well as REGEXTEST and REGEXEXTRACT use the PCRE2 ‘flavor’ of regex.
REGEXEXTRACT always return text values. You can convert these results back to a number with the VALUE function.