Writing regular expressions
Your marketing director needs to see how some campaigns and ad groups are performing. The performance of the campaigns and ad groups will determine the strategy for the upcoming quarter, so it is very important that the filtering is correct. Regular expressions are a great way to filter the campaigns and ad groups. Here are some examples to help you out:
- You can use square brackets
[]
to match one of a set of characters. For example, if you wanted to match words beginning with a lower-casea
or a lower-caseb
, you could use the pattern^[a|b].*
. The^
character marks the beginning of a word, and the.*
matches any characters that follow ana
or ab
. - You can define the end of a string by using the anchor
$
. For example,.*ly$
would matchFinally
andGladly
. - If you want to check for one of two regular expression components, you can use the pipe operator
|
. For example,Steve|Sarah
would matchSteve
orSarah
.
The requests are simple. The first performance group the marketing director would like to see should contain the performance metrics for all Python and Python related campaigns, such as pandas. The second performance group is to understand how the branded campaigns are performing. The last performance group is a special interest case, where the marketing director would like to see how the Mugs
and Sweaters
ad groups are performing.
This exercise is part of the course
Marketing Analytics in Google Sheets
Exercise instructions
Use the examples above to help you write the following regular expressions. Note: after entering your formula, make sure to select another cell or press 'Enter' to allow the grader to evaluate your pattern.
- Write a regular expression in cell
H3
that will include all of thecampaigns
that begin with the characterp
orP
(i.e. both upper-case and lower-case). - In cell
H4
, write a regular expression that will include any campaign that ends with the letterd
. - For cell
H5
, write a regular expression that will select ad groupsMugs
andSweaters
.
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
