regex_replace

Searches a value for text that matches a regular_expression , then replaces the matching text with new_text .

Note: This function is only available in Templates and can’t be used in Reporting.

Regular expressionsis a powerful language for matching patterns of partial words, whole words, or even multiple words. While basic regular expressions are straightforward to use, you can create complex expressions that are powerful but may be difficult to predict and debug --- and may be difficult for other people in your organization to understand.

So the best practice is: start with the basics, and add complexity only if you have no other choice.

Syntax

regex_replace("value", "regular_expression", "replacement")

Parameters

string and replacement can be any of the following:

  • Static text, such as "GDN".
  • An expression or formula column that returns a text value. This is often a feed attribute.
    When using feed attributes, ensure that the attribute contains the expected data and is free of errors such as missing values or invalid characters.

regular_expression is a case-sensitiveRE2 regular expression ( RE2is an open source engine for processing regular expressions). Find examples and suggestions mentioned below. The complete list of operators and syntax is available on Github .

Surround the regular expression with quotation marks.

Regular expression syntax

Here's a list of the operators and syntax you may find useful when using regular expressions in Search Ads 360:

Wildcards

. Matches any single character (letter, number or symbol) goo.glematches gooogle, goodgle, goo8gle
* Matches zero or more of the previous item The default previous item is the previous character. goo*glematches gooogle, goooogle
+ Matches one or more of previous item gooo+glematches goooogle, but not  google.
? Matches zero or one of the previous item labou?rmatches both laborand labour
| Inclusive "or"  a|bmatches aor b, or both aand b

Anchors

^ Line starts with ^sitematches sitebut not mysite
$ Line ends with site$matches sitebut not sitescan

Grouping

() Capturing group Thank(s|you) matches both Thanksand Thankyou
[] Set or range of characters in any order [ogl]+ matches google,   goooogle, or logic
- Expresses a range of characters [A-Z]creates a list for the uppercase English alphabet

Other

\ Escape special characters mysite\.comkeeps the dot from being a wildcard
\s Space character \s+.* matches one or more whitespace followed by zero or more characters
\d Digit \d65\dmatches "265" not "256"
\w Word character (a-z, A-Z, 0-9, _) $\wmatches any string starting with a word character, such as "Campaign" but not "@Campaign"
\b Word boundary \bcity\bmatches " city " not "scarcity"

Examples

  • regex_replace(ITEM_TITLE, "\bLabou?r\b", "Fun")

If ITEM_TITLE is "Ministry of Labour" or "Ministry of Labor", the function returns "Ministry of Fun".
If ITEM_TITLE is "Ministry of labor", the function does not find a match. ( regular_expression in Search Ads 360 is case-sensitive)
Note that \b is needed to prevent matching "Laborious." For example:
regex_replace(ITEM_TITLE, "Labou?r", "Fun")
If ITEM_TITLE is "Laborious Hike", the function returns "Funious Hike".

Example of removing invalid characters:

  • regex_replace(ITEM_TITLE, "[!@#$%-()^*={};~`<>?|/]", "")

If ITEM_TITLE  is "MyProduct@123" or "MyProduct(123)", the function returns "MyProduct123".

Related links

Was this helpful?

How can we improve it?

Need more help?

Try these next steps:

true
Search
Clear search
Close search
Google apps
Main menu
3686815561391497238
true
Search Help Center
false
true
true
true
true
true
5055977
true
false
false
false
Design a Mobile Site
View Site in Mobile | Classic
Share by: