首页 > 解决方案 > Need Help Rewriting Regex with only 1 Capturing Group

问题描述

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"}

标签: regexgoogle-bigquery

解决方案


以下是 Bigquery 标准 SQL

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

如果适用于您问题中的示例行 - 输出是

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

推荐阅读