首页 > 其他 > 详细

Hive 正则匹配函数 regexp_extract

时间:2016-02-01 18:14:00      阅读:715      评论:0      收藏:0      [点我收藏+]

参考自 http://www.tuicool.com/articles/Rfmeiy

regexp_extract

语法:    regexp_extract(string subject,  string pattern,  int index)

返回值: string

说明:  将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。

 

例如:‘匹配 10.122.248’

select regexp_extract(host, ‘(^[\\w]+)\\.([\\w]+)\\.([\\w]+)‘,0) aa

from browsewebpagelog where dt like ‘20140630%‘;

第一参数:   要处理的字段

第二参数:    需要匹配的正则表达式

第三个参数: 0是显示与之匹配的整个字符串,1,是显示第一个括号里面的,2是显示第二个括号里面的字段...

 

注意,在有些情况下要使用转义字符(双斜杠了‘\\’)。

举例:

select regexp_extract(‘foothebar’,  ‘foo(.*?)(bar)’,  1) from dual;

the

select regexp_extract(‘foothebar’,  ‘foo(.*?)(bar)’,  2) from dual;

bar

select regexp_extract(‘foothebar’,  ‘foo(.*?)(bar)’,  0) from dual;

foothebar

 

Hive 正则匹配函数 regexp_extract

原文:http://www.cnblogs.com/skyEva/p/5175377.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!