Use regular expressions in filters and automated rules
Updated by: LunaMetrics on March 8, 2008
When you set up filters or automated rules, you use pattern matching to specify just the campaigns, ad groups, ads, or biddable items that you care about. If your patterns are relatively simple, such as "Show campaigns that contain ' - GB AdWords' in their names, you can use the basic pattern matching that DS provides. If your patterns are more complex, such as "Show campaigns with names that start with 'AdWords' and end with 'GB' or "US'", you can use regular expressions.
Regular expressions is a powerful language for matching patterns of partial words, whole words, or even multiple words. While simple 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 simple, and add complexity only if you have no other choice.
Set up a regular expression filter or rule
Select a setting or metric from the + Attribute or metric list.
Select any additional criteria from the next + Attribute or metric list. The filter or rule will match only the items that match all criteria.
Finish creating the filter or rule.
Start with filters, and build interactively. If you're planning on using a regular expression in a rule, start with filtering a report using the most simple expression and see what matches. Then add wildcards, anchors, or other parts of an expression and test each step of the way. Once you're happy with the filter, you can use the same regular expression in automatic rules.
For example, on the Campaigns tab, start with
and confirm that you see only campaigns with names that start with "AdWords ".
Then change the filter to:
and confirm that you see only campaigns with names that start with "AdWords " and end with " GB".
Finally, change the filter to:
(^AdWords\b).+(GB\b$ | US\b$)
and confirm that you see only campaigns with names that start with "AdWords " and end with " GB" or "US".
Regular expression syntax
Here's a list of the operators and syntax you may find useful when using regular expressions in DS:
. Matches any single character (letter, number or symbol) goo.gle matches gooogle, goodgle, goo8gle * Matches zero or more of the previous item The default previous item is the previous character. goo*gle matches gooogle, goooogle + Matches one or more of previous item gooo+gle matches goooogle, but not google. ? Matches zero or one of the previous item labou?r matches both labor and labour | Inclusive "or" a|b matches a or b, or both a and b
^ Line starts with ^site matches site but not mysite $ Line ends with site$ matches site but not sitescan
() Non-capturing group Thank(s|you) matches both Thanks and 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
\ Escape special characters mysite\.com keeps the dot from being a wildcard \s Space character \s+.* matches one or more whitespace followed by zero or more characters \d Digit \d65\d matches "265" not "256" \w Word character (a-z, A-Z, 0-9, _) $\w matches any string starting with a word character, such as "Campaign" but not "@Campaign" \b Word boundary \bcity\b matches " city " not "scarcity"
|(^AdWords\b).+(GB\b$ | US\b$)||
Starts with "AdWords" and ends with "GB" or "US"
Does not match: