【问题标题】:I need to extract all the characters on the right side of a matching character using BigQuery我需要使用 BigQuery 提取匹配字符右侧的所有字符
【发布时间】:2021-01-19 05:27:13
【问题描述】:

我想使用 BigQuery 提取位于匹配字符右侧的所有字符。 例如: 假设我想提取 '-' 右边的所有字符 那么:

  1. happy-holiday will give holiday
  2. gogoa-gone 会放弃的

谁能帮我解决这个问题

【问题讨论】:

    标签: google-bigquery data-analysis


    【解决方案1】:

    试试SPLIT:

    SELECT SPLIT("happy-holiday will give holiday", "-")[OFFSET(1)]
    

    REGEXP_EXTRACT:

    SELECT REGEXP_EXTRACT("happy-holiday will give holiday", r"-(.*)")
    

    【讨论】:

      【解决方案2】:

      Sergey 提到的 SPLIT 效果很好.. 或者你可以用老派的方式来做 :)

          WITH sample_data AS (
            SELECT 'happy-holiday' as text
          UNION ALL
            SELECT 'gogoa-gone' as text
          UNION ALL
            SELECT 'hello-world' as text
          UNION ALL
            SELECT 'i-am-back' as text
          UNION ALL
            SELECT 'hey-whatever is after the dash' as text
          )
          
          SELECT text
          , instr(text, '-', -1) as dash_position
          , substr(text, instr(text, '-', -1)+1, length(text)) as substr
          FROM sample_data
      

      结果:

          TEXT                            DASH_POSITION   SUBSTR
          ---------------------------------------------------------------------------
          happy-holiday                   6               holiday
          gogoa-gone                      6               gone
          hello-world                     6               world
          i-am-back                       5               back
          hey-whatever is after the dash  4               whatever is after the dash
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多