【问题标题】:BigQuery : Regex after a stringBigQuery:字符串后的正则表达式
【发布时间】:2016-10-10 20:23:38
【问题描述】:

我有一列的值为 source:destination:city:street:number,我想只获取没有 : 的城市。

我该怎么做?

提前致谢

【问题讨论】:

    标签: regex google-bigquery


    【解决方案1】:

    我该怎么做?

    适用于 BigQuery 方言:旧版 SQL 和标准 SQL

    SELECT 
      REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){2}(.+)(?::.+){2}')  
    

    查看更多 REGEXP_EXTRACTre2 syntax

    如果我需要源后面的第一个词:例如?

    SELECT 
      REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){1}(.+)(?::.+){3}')  
    

    这里有很多选项供您选择,具体取决于您的具体需求
    下面是另一个(BigQuery Legacy SQL)

    SELECT 
      NTH(1, SPLIT(text,':')) AS source,
      NTH(2, SPLIT(text,':')) AS destination,
      NTH(3, SPLIT(text,':')) AS city,
      NTH(4, SPLIT(text,':')) AS street,
      NTH(5, SPLIT(text,':')) AS number
    FROM (
      SELECT 'source:destination:city:street:number' AS text
    )
    

    【讨论】:

    • 感谢您的回答,如果我需要source后面的第一个词:例如?
    猜你喜欢
    • 2019-11-09
    • 1970-01-01
    • 2015-08-22
    • 2020-01-25
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多