Hive and regular expression

前端 未结 1 1374
长情又很酷
长情又很酷 2020-12-10 21:27

I am trying to filter all the ip adresses in a username. But this doesnt really work properly in my query:

select distinct regexp_extract(username, \'^([0-9]         


        
1条回答
  •  萌比男神i
    2020-12-10 21:28

    You need extra backslashes to escape special characters like . or \s. There's some more info on the wiki at https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

    Try something like:

    select
        distinct regexp_extract(ip, '^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$', 0) as match
    from
        ips
    having
        match <> "";
    

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