hive函數 regexp_extract
語法描述
老的函數格式
regexp_extract(string subject, string pattern[, index])
最新的函數格式:
regexp_extract(string subject, string pattern, int index)
Returns the string extracted using the pattern. For example, regexp_extract('foothebar', 'foo(.*?)(bar)', 2) returns 'bar.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\s' is necessary to match whitespace, etc. The 'index' parameter is the Java regex Matcher group() method index. See docs/api/java/util/regex/Matcher.html for more information on the 'index' or Java regex group() method.
參數解釋:
subject 是被解析的字符串
pattern 是正則表達式
index 是返回結果,取表達式的哪一部,默認值為1。
0表示把整個正則表達式對應的結果全部返回;
1表示返回正則表達式中第一個() 對應的結果 以此類推。
注意點:
要注意的是idx的數字不能大於表達式中()的個數。
否則報錯