【问题标题】:Extract any and all characters between " " using Big Query REGEX使用 Big Query REGEX 提取“”之间的所有字符
【发布时间】:2019-12-05 20:13:55
【问题描述】:

我只需要从这个较大的字符串中提取 '"Loc":"CART",':

hits_eventInfo_eventLabel = {"AV":6,"CV":1,"PV":1,"AS":"1,2,3,4","Loc":"CART","PN":"Supreme Lover's® - 12\" Medium","PS":"6716a12c-0067-4d72-b560-a0dbd1197185"}

“Loc”将始终保持不变,“CART”所在的值可能会改变。

我正在尝试以下 sql:

REGEXP_EXTRACT(hits_eventInfo_eventLabel, '"Loc":".*",') as Recommendation_Location

但它会返回从“Loc”之后开始的整个其余字符串。

我在 Google BigQuery 中使用标准 sql,并且一直在查看所有文档,但似乎无法弄清楚如何仅获取引号内的字符。

任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: regex google-bigquery


    【解决方案1】:

    以下是 BigQuery 标准 SQL

    代替

    REGEXP_EXTRACT(hits_eventInfo_eventLabel, '"Loc":".*",')   
    

    返回

    Row Recommendation_Location  
    1   "Loc":"CART","PN":"Supreme Lover's® - 12" Medium",   
    

    使用

    REGEXP_EXTRACT(hits_eventInfo_eventLabel, '"Loc":".*?",')   
    

    返回

    Row Recommendation_Location  
    1   "Loc":"CART",    
    

    如您所见,唯一的区别是 - 您需要在正则表达式中添加额外的 ? char

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多