正则表达式解析函数: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;
语法: 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),',','\\#\\*\\#\\#')