Google Sheets REGEXREPLACE Function

This post will guide you how to use Google Sheets REGEXREPLACE function with syntax and examples.

Description


The Google Sheets REGEXREPLACE function is to replace a part of a text string with a different substring using regular expressions.

The REGEXREPLACE function can be used to replace a substring from a text string according to a given regular expression in google sheets.

The REGEXREPLACE function is a build-in function in Google Sheets and it is categorized as a Text Function. And The REGEXREPLACE function is one of the three REGEX functions (REGEXEXTRACT, REGEXMATCH and REGEXREPLACE )in google sheets.

Syntax


The syntax of the REGEXREPLACE function is as below:

=REGEXREPLACE (text, regular_expression, replacement)

Where the REGEXREPLACE function arguments are:

  • text -This is a required argument. The text string that you want to extract a substring based on regular expression.
  • regular_expression – This is a required argument. The Regular_expression is a regular expression. It can be used to match the part of the text that you want to extract. The regular expression argument should be entered in double-quote characters. And Regular_expression is a search patterns that allow you to find a certain patterns in original text string.
  • Replacement – The text which will be inserted into the original text.

Note: 

  • The REGEXREPLACE function takes two arguments. It checks whether a piece of text matches a given regular expression.
  • The REGEXREPLACE function only works with text value as its first argument and returns a text result. If you wish to return a numeric value, and you need to use VALUE function in combination with the REGEXREPLACE function. If the input value is a number, and you can use the TEXT function to convert them.
  • Google Sheets supports RE2 for regular expressions.

Google Sheets REGEXREPLACE Function Examples


The below examples will show you how to use google sheets REGEXREPLACE function to replace a substring from a text according to a regular expression.

#1 Replace all “google” keywords with “mygoogle” text string, and you can use the REGEXREPLACE function with a regular expression “google”, type:

=REGEXREPLACE(B1,"google","mygoogle") //it returns “mygoogle 2021 sheets 2020”

google sheets regexreplace function

#2 Replace all word with “mygoogle” substring from a string in cell B1, and you can use the REGEXREPLACE function with a regular expression “\w+”, type:

=REGEXREPLACE(B1,"\w+","mygoogle") //it returns “mygoogle mygoogle mygoogle mygoogle”

google sheets regexreplace function

#3 Replace the last whole word from a string using REGEXREPLACE function with a regular expression “\w+$”, type:

=REGEXREPLACE(B1,"\w+$","mygoogle") // it returns “google 2021 sheets mygoogle”

google sheets regexreplace function

#4 Replace all numbers with “2025” from a string in cell B1 and you can use the REGEXREPLACE function with a regular expression “\d+”, type:

=REGEXREPLACE(B1,"\d+","2025") // it returns “google 2025 sheets 2025”

google sheets regexreplace function

#5 Replate the last number with “2025” number from a string in cell B1, and you can use the REGEXREPLACE function with a regular expression “\d+$”, type:

=REGEXREPLACE(B1,"\d+$","2025") // it returns “google 2021 sheets 2025”

google sheets regexreplace function

 

 

Related Posts

Google Sheets NOW Function
google sheets now function1

This post will guide you how to use Google Sheets NOW function with syntax and examples. Description The Google Sheets NOW function returns the serial number of the current date and time. And it will be updated each time when ...

Google Sheets NETWORKDAYS.INTL Function
google sheets networkdays.intl function1

This post will guide you how to use Google Sheets NETWORKDAYS.INTL function with syntax and examples. Description The Google Sheets NETWORKDAYS.INTL function returns the number of net working days between tow given days excluding specified weekend days and holidays. The ...

Google Sheets NETWORKDAYS Function
google sheets networkdays function1

This post will guide you how to use Google Sheets NETWORKDAYS function with syntax and examples. Description The Google Sheets NETWORKDAYS function returns the number of net working days between tow given days. The NETWORKDAYS function can be used to ...

Google Sheets MONTH Function
google sheets month function1

This post will guide you how to use Google Sheets MONTH function with syntax and examples. Description The Google Sheets MONTH function returns the month of a date represented by a serial number. And the month is an integer number ...

Google Sheets MINUTE Function
google sheets minute function1

This post will guide you how to use Google Sheets MINUTE function with syntax and examples. Description The Google Sheets MINUTE returns the minutes of a time value. And the minutes is an integer number from 0 to 59. So ...

Google Sheets ISOWEEKNUM Function
google sheets isoweeknum function1

This post will guide you how to use Google Sheets ISOWEEKNUM function with syntax and examples. Description The Google Sheets ISOWEEKNUM returns the number of the ISO week of the year for a given date. ISO weeks begin on Monday ...

Google Sheets HOUR Function
google sheets hour function1

This post will guide you how to use Google Sheets HOUR function with syntax and examples. Description The Google Sheets HOUR returns the hour of a time value. Or returns an integer value that represent the hour component of a ...

Google Sheets EOMONTH Function
google sheets eomonth function1

This post will guide you how to use Google Sheets EOMONTH function with syntax and examples. Description The Google Sheets EOMONTH returns a date representing the last day of the month, n months in the future or past. The EOMONTH ...

Google Sheets EDATE Function
google sheets edate function1

This post will guide you how to use Google Sheets EDATE function with syntax and examples. Description The Google Sheets EDATE returns a date that is a specified number of months before or after a specified date. You can use ...

Google Sheets DAYS360 Function
google sheets days360 function1

This post will guide you how to use Google Sheets DAYS360 function with syntax and examples. Description The Google Sheets DAYS360 will calculate the number of days between two dates based on a 360-day year. The DAYS360 function can be ...

Sidebar