参考自 http://www.tuicool.com/articles/Rfmeiy
语法: 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
原文:http://www.cnblogs.com/skyEva/p/5175377.html