[UA] Parentheses ( ) and pipe |

Parentheses ( )

Use parentheses to group parts of an expression together.

For example, if you need to match a set of characters that appear in a number of different product SKUs, then you can group those characters together in parentheses. Say you have a beach sandal that you sell for men and women, and your product SKUs look like this:

  • MNBS010212 (men’s beach sandal, style 01, color 02, size 12)
  • WMBS020208 (women’s beach sandal, style 02, color 02, size 08)

You could create the following regular expression to capture all beach-sandal SKUs:

\D+(BS)\d+

  • \D (non-numeric character)
  • + (one or more times)
  • (BS) (character code for beach sandal)
  • \d (numeric character)
  • + (one or more times)

Pipe |

Use the pipe to create an OR condition in an expression.

For example, if you wanted to create a segment that included data for your Spring campaign in London and Paris, you would configure the segment as follows:

  • Campaign exactly matches Spring
  • City matches regex London|Paris

You can also use the pipe within parentheses. For example, here’s another way to create the expression to match your beach-sandal SKUs:

(MN|WM)BS\d+

  • (MN OR WM)
  • BS (character code for beach sandals)
  • \d (numeric character)
  • + (one or more times)

Was this helpful?

How can we improve it?
true
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Search
Clear search
Close search
Google apps
Main menu
7147581383983190837
true
Search Help Center
true
true
true
true
true
69256
false
false