【问题标题】:Extracting digits after certain characters that appear more than once from a string field in Hive从 Hive 中的字符串字段中提取多次出现的某些字符后的数字
【发布时间】:2021-09-07 10:15:51
【问题描述】:

我正在尝试提取出现在 'dd ->' 之后的所有数字

我已经想出如何在“dd ->”之后提取第一次出现的数字:regexp_extract(string, 'dd\\s->\\s([0-9]+)') 以及如何替换除数字以外的所有字符 regexp_replace(string, '[^0-9]+', '')但没找到解决办法

字符串: (dd -> 2192, bar -> 1), (dd -> 2670, bar -> 1), (dd -> 2487, bar -> 3),(dd -> 2346, bar -> 3) kk=67457 ghyt=1628 nn=8.67.1

期望的输出: 2192 2670 2487 2346

谢谢!

【问题讨论】:

    标签: regex hiveql regexp-replace


    【解决方案1】:

    使用

    dd ->( [0-9]+)|.
    

    替换为 $1

    regex proof

    解释

    --------------------------------------------------------------------------------
      dd ->                    'dd ->'
    --------------------------------------------------------------------------------
      (                        group and capture to \1:
    --------------------------------------------------------------------------------
                                 ' '
    --------------------------------------------------------------------------------
        [0-9]+                   any character of: '0' to '9' (1 or more
                                 times (matching the most amount
                                 possible))
    --------------------------------------------------------------------------------
      )                        end of \1
    --------------------------------------------------------------------------------
     |                        OR
    --------------------------------------------------------------------------------
      .                        any character except \n
    

    如果需要,修剪第一个空格。

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 1970-01-01
      • 2021-07-03
      • 2017-08-20
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多