Strange behaviour of Regexp_replace in a Hive SQL query

后端 未结 1 1881
误落风尘
误落风尘 2021-01-17 01:06

I have some input information where I\'m trying to remove the part .0 from my input where an ID string ends with .0.

select student_i

相关标签:
1条回答
  • 2021-01-17 01:42

    Dot in regexp has special meaning (it means any character). If you need dot (.) literally, it should be shielded using double-slash (in Hive). Also add end-of-the-line anchor($):

    with mydata as (
    select stack(3,
    '01-0230984.03',
    '12345098.0',
    '34567.0'
    ) as str
    )
    
    select regexp_replace(str,'\\.0$','') from mydata;
    

    Result:

    01-0230984.03
    12345098
    34567
    

    Regexp '\\.0$' means dot zero (.0) literally, end of the line ($).

    0 讨论(0)
提交回复
热议问题