Solved

glob Matching a list of patterns

  • 21 April 2021
  • 1 reply
  • 52 views

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?

icon

Best answer by tracy.guo 21 April 2021, 23:51

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

1 reply

Userlevel 4
Badge +3

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!

Reply