Syntax
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])Arguments
| Argument | Required | Description |
|---|---|---|
text | Required | The text to change |
pattern | Required | The regular expression |
replacement | Required | The replacement text ($1, $2 insert capture groups) |
occurrence | Optional | 0 replaces all matches (default); n only the nth, negative counts from the end |
case_sensitivity | Optional | 0 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 =REGEXREPLACE("John Smith", "(\w+) (\w+)", "$2, $1")Result =REGEXREPLACE("a-b-c", "-", "+", 2)Result Related text functions
- PHONETICReturns the phonetic (furigana) text of a cell; here that is the text of the cell itself.
- PROPERCapitalizes the first letter of each word and makes the other letters lowercase.
- REGEXEXTRACTReturns the parts of a text that match a regular expression pattern.
- REGEXMATCHChecks whether any part of a text matches a regular expression pattern (case sensitive).
- REGEXTESTChecks whether any part of a text matches a regular expression pattern.
- REPLACEReplaces part of a text, given a start position and a number of characters, with other text.
- REPLACEBSame as REPLACE, counting bytes; without a double byte language set as default each character counts as one byte.
- REPTRepeats text a given number of times.
- RIGHTReturns the last characters of a text.