仅需一个捕获组即可帮助重写正则表达式 [英] Need Help Rewriting Regex with only 1 Capturing Group

查看:50
本文介绍了仅需一个捕获组即可帮助重写正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的正则表达式提取了我所需要的,但是我在BigQuery中遇到此错误:

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

传递给REGEXP_EXTRACT_ALL的正则表达式不得具有多个捕获组"

我试图摆脱第二个捕获小组,但不知道如何获得相同的结果.预期结果是:

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":关闭","split.attribute2":"20off","split.attribute3":排除"]

正则表达式:

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

样本数据:

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

推荐答案

以下是Bigquery标准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"   

这篇关于仅需一个捕获组即可帮助重写正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆