What are regular expressions?

Marketing Analytics in Google Sheets

Luke Pajer

Digital Marketing Specialist

Digital marketing table

Digital Marketing Table

Marketing Analytics in Google Sheets

Digital marketing table

Digital Marketing Table 2

Marketing Analytics in Google Sheets

Answer: use regular expressions

  • What are regular expressions?
    • A special search pattern
    • Made of a sequence of characters
    • Also known as 'regex'
  • When are they used?
    • To search within strings
    • Commonly used when filtering by categories
  • How to get both R users and Python Users?
Marketing Analytics in Google Sheets

Regular expression for users

Breaking down the regular expression that will match all campaigns ending in users:

regular_expression = .*[u|U]sers

  • .* - matches any number of characters preceding the word 'users'
  • u|U - matches either the lower or upper case variation of letter 'u'
  • [u|U]sers - matched terms must contain one of the items within the brackets

Three regular expression metacharacter categories: Wildcards, Anchors, and Groups.

Marketing Analytics in Google Sheets

Basic regular expression characters: wildcards

Wildcards:

  • . matches any character
  • * matches 0 or more times
  • ? matches 0 or 1 time
  • + matches 1 or more times
  • x|y matches x OR y
  • \ escapes any special character

Examples:

  • d.g matches both 'dog' and 'dig'
  • .* matches all the letters in 'dog'
  • dogs? matches either 'dog' or 'dogs'
  • dog.+ matches 'dogs' but not 'dog'
  • dog|cat matches either 'dog' or 'cat'
  • who\? matches 'who?'
1 https://support.google.com/analytics/answer/1034324?hl=en
Marketing Analytics in Google Sheets

Basic regular expression characters: anchors

Anchors

  • ^x the start of a string
  • x$ the end of a string

Examples

  • ^T matches 'The dog likes to dig'
  • g$ matches 'The dog likes to dig'
1 https://support.google.com/analytics/answer/1034324?hl=en
Marketing Analytics in Google Sheets

Basic regular expression characters: groups

Groups

  • [x|X] matches either 'x' or 'X'
  • {x} matches x number of times

Examples

  • [d|D]og matches either 'dog' or 'Dog'
  • .{2} matches 'Do' in 'Dog'
1 https://support.google.com/analytics/answer/1034324?hl=en
Marketing Analytics in Google Sheets

Let's get to work!

Marketing Analytics in Google Sheets

Preparing Video For Download...