Hive 和正则表达式 [英] Hive and regular expression
本文介绍了Hive 和正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试过滤用户名中的所有 IP 地址.但这在我的查询中并不能正常工作:
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,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$', 0) from ips.
问题是他甚至将数字识别为 1000000 作为 IP 地址.知道如何修复它吗?
The problem is that he even recognizes numbers as 1000000 as ip adress. Any idea how to fix it?
推荐答案
你需要额外的反斜杠来转义像 .或s.维基上有更多信息 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
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
尝试以下操作:
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 <> "";
这篇关于Hive 和正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文