Skip to main content
Solved

glob Matching a list of patterns


Hey there,

I would like to add a where clause to an event with the property query. I have a long list of values, so instead of adding each value one by one I would like to use glob matching.

Usually the syntax would be 

?(dog|cat|zebra)

But this does not work (no event matches).

What is the correct way to do this in Amplitude?

Best answer by tracy.guo

Hi @vpillac ! Great question.

In this case, I’d recommend using the “contains” operator instead of the glob match operator. You can add where ‘query’ contains and then paste a comma separated list into the values section (eg dog,cat,zebra). From here, the dropdown menu can parse the comma separated list and you should be able to click “Select All” to add all three values to the filter. Now any query value that contains dog or cat or zebra will be returned.

More information on adding a list of values can be found here: https://help.amplitude.com/hc/en-us/articles/360035354552#adding-a-list-of-property-values

The reason I don’t think glob match is a good fit here is that when glob matching, the “?” wildcard matches on a single character and unlike regex, glob match does not typically support the “|” operator. Glob match could potentially work if you glob match for *dog*,*cat*, and *zebra*, which should produce the same results as the contains operator, except that glob match is also case sensitive, so only lower cased dog, cat, and zebra values will be returned. 

More information on glob match syntax can be found here: https://en.wikipedia.org/wiki/Glob_(programming)#Syntax

Do you think the “contains” operator works for your use case? Let me know your thoughts and if you have any questions!

View original
Did this topic help you find an answer to your question?

3 replies

tracy.guo
Team Member
Forum|alt.badge.img+3
  • Amplitude Support
  • 39 replies
  • Answer
  • April 21, 2021

Hi @vpillac ! Great question.

In this case, I’d recommend using the “contains” operator instead of the glob match operator. You can add where ‘query’ contains and then paste a comma separated list into the values section (eg dog,cat,zebra). From here, the dropdown menu can parse the comma separated list and you should be able to click “Select All” to add all three values to the filter. Now any query value that contains dog or cat or zebra will be returned.

More information on adding a list of values can be found here: https://help.amplitude.com/hc/en-us/articles/360035354552#adding-a-list-of-property-values

The reason I don’t think glob match is a good fit here is that when glob matching, the “?” wildcard matches on a single character and unlike regex, glob match does not typically support the “|” operator. Glob match could potentially work if you glob match for *dog*,*cat*, and *zebra*, which should produce the same results as the contains operator, except that glob match is also case sensitive, so only lower cased dog, cat, and zebra values will be returned. 

More information on glob match syntax can be found here: https://en.wikipedia.org/wiki/Glob_(programming)#Syntax

Do you think the “contains” operator works for your use case? Let me know your thoughts and if you have any questions!


Forum|alt.badge.img
  • Novice
  • 3 replies
  • April 24, 2023

What about if I am trying to write a formula in derived properties, where I am using the following line:

IF( REGEXEXTRACT($2, 'DI|EM|SL') == 'DI|EM|SL', 'lodge',

It seems that neither pipe nor comma work in this case as an ‘or’


Esther Trapadoux
Community Manager
Forum|alt.badge.img+9

@Eva Bell good question.

In your formula, you are using the pipe symbol | inside the regular expression 'DI|EM|SL' to match any of the three strings "DI", "EM", or "SL". However, when you compare the result of REGEXEXTRACT($2, 'DI|EM|SL') to the string 'DI|EM|SL', you are comparing the matched string to a literal string that includes the pipe symbol.

To compare the matched string to any of the three strings "DI", "EM", or "SL", you can use the IN operator, which checks whether a value is included in a list of values. For example:

IF(REGEXEXTRACT($2, 'DI|EM|SL') IN ('DI', 'EM', 'SL'), 'lodge', ...)

This formula checks whether the result of REGEXEXTRACT($2, 'DI|EM|SL') is included in the list of strings ('DI', 'EM', 'SL'), and if so, it returns the string 'lodge'.

Note that in this case, you should not include the pipe symbol | in the comparison string. Instead, you should provide a list of possible values as separate strings inside parentheses, separated by commas.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings