Need Help Rewriting Regex with only 1 Capturing Group

Viewed 3729

The below regex extracts what I need but I am getting this error in BigQuery:

"Regular expression passed to REGEXP_EXTRACT_ALL must not have more than 1 capturing group"

I tried to get rid of the 2nd capturing group but can't figure out how to get the same results. Expect the results to be:

["split.attribute1": "off","split.attribute2": "20off","split.attribute3": "excluded"]

Regex:

(?:"split(.*?)": ")(.*?)(?:")

Sample Data:

{"split.attribute1": "off", "hostname": "www.test.com", "split.attribute2": "20off", "split.attribute3": "excluded"}
1 Answers

Below is for Bigquery Standard SQL

#standardSQL
SELECT REGEXP_EXTRACT_ALL(data, r'("split..*?)(?:,|})') attributes
FROM `project.dataset.table`  

if to apply to sample row in your question - output is

Row attributes   
1   "split.attribute1": "off"    
    "split.attribute2": "20off"  
    "split.attribute3": "excluded"   
Related