I'm trying to use BigQuery's REGEXP_EXTRACT_ALL function to parse "search queries" of the form operator: query. There can be multiple operator/query pairs in a query string, and the "subquery" that falls under an operator can have multiple words enclosed by parens. I'd like to extract only the "search operators" from the query string using a regular expression.
For example:
- animal: cat -> ["animal"]
- animal: (mountain lion) -> ["animal"]
- month: february day: sunday -> ["month", "day"]
- date: (july 31) weather: (blue sky) -> ["date", "weather"]
Any suggestions? I'm definitely a regex noob, the best I've done so far is
REGEXP_EXTRACT_ALL(query, "(.\*):") AS operator
which recursively expands all of the text seen before colons (giving me results like ["date", "date: (july 31) weather"]).
One last "advanced" feature I'd like to implement is only including search operators if they are fully made up of text. For example:
time: 2020-07-08T17:09:14.043Z -> ["time"]
Thanks!
