使用 HiveQL 替换字符串中首次出现的字符

Replacing first occurence of character in a string using HiveQL

我正在尝试替换 Hive table 中字符串中第一次出现的 '-'。我正在使用 HiveQL。我在这里和其他网站上搜索了这个主题,但找不到明确的解释如何使用 regexp_replace() 的元字符来做到这一点。

这是一个字符串,我需要将其中的第一个“-”替换为空 space:16-001-02707 结果应该是这样的:16001-02707 这是我使用的方法:

select regexp_replace ('16-001-02707','[^[:digit:]]', '');

但是,这没有任何作用。

select regexp_replace ('16-001-02707','^(.*?)-', '');

16001-02707


在评论中关注OP问题

with t as (select '111-22-333333-4-555-6-7-8888-999999' as col)

select  regexp_replace (col,'^(.*?)-','')
       ,regexp_replace (col,'^(.*?-.*?)-','')
       ,regexp_replace (col,'^((.*?-){2}.*?)-','')
       ,regexp_replace (col,'^((.*?-){3}.*?)-','')
       ,regexp_replace (col,'^((.*?-){4}.*?)-','')
       ,regexp_replace (col,'^((.*?-){5}.*?)-','')

from    t

+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+
|                _c0                 |                _c1                 |                _c2                 |                _c3                 |                _c4                 |                _c5                 |
+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+
| 11122-333333-4-555-6-7-8888-999999 | 111-22333333-4-555-6-7-8888-999999 | 111-22-3333334-555-6-7-8888-999999 | 111-22-333333-4555-6-7-8888-999999 | 111-22-333333-4-5556-7-8888-999999 | 111-22-333333-4-555-67-8888-999999 |
+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+------------------------------------+