hive函数-regexp_extractd的例子

来源:互联网 发布:cctv7观军事知天下视频 编辑:程序博客网 时间:2024/05/22 14:15
正则表达式解析函数:regexp_extract
语法: regexp_extract(string subject, string pattern, int index) 
返回值: string
说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。注意,在有些情况下要使用转义字符
举例:
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 1) from dual;
the
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 2) from dual;
bar
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 0) from dual;

foothebar


提取IP地址:

regexp_extract(ip_address, '([^.]*)\.([^.]*)\.([^.]*)\.', 0 )


提取字符后面的字符串:
 select  regexp_extract('008600214091141 3|深圳市', '.*\\|(.*)', 1)

regexp_extract(‘asdf{asdfs{sdbdd}}’, '^([^\\{]{0,})\\{',1)


替换json分隔的逗号成别的分隔符

regexp_replace(regexp_extract(defined_head, '^[^\{]{0,}(\\{.*\\})[^\}]{0,}$', 1),',','\\#\\*\\#\\#')

0 0
原创粉丝点击