需要帮助仅用 1 个捕获组重写正则表达式 [英] Need Help Rewriting Regex with only 1 Capturing Group
本文介绍了需要帮助仅用 1 个捕获组重写正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下正则表达式提取了我需要的内容,但在 BigQuery 中出现此错误:
The below regex extracts what I need but I am getting this error in BigQuery:
传递给 REGEXP_EXTRACT_ALL 的正则表达式不能有超过 1 个捕获组"
我试图摆脱第二个捕获组,但不知道如何获得相同的结果.预期结果是:
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"]
正则表达式:
(?:"split(.*?)": ")(.*?)(?:")
示例数据:
{"split.attribute1": "off", "hostname": "www.test.com", "split.attribute2": "20off", "split.attribute3": "excluded"}
推荐答案
以下是 Bigquery Standard SQL
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"
这篇关于需要帮助仅用 1 个捕获组重写正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文