美文网首页
hive 匹配正则表达式

hive 匹配正则表达式

作者: cyangssrs | 来源:发表于2019-07-15 11:06 被阅读0次

    regexp (same as rlike)

    operator operand types description
    A rlike B strings NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java regular expression B, otherwise FALSE. For example, 'foobar' RLIKE 'foo' evaluates to TRUE and so does 'foobar' RLIKE '^f.*r$'.
    A regexp B strings same as rlike

    A(string) regexp B(正则表达式)

    select * from table_name where column1 regexp '[正则表达式]' 
    and column2 not regexp '[正则表达式]'
    

    regexp_extract、regexp_replace

    return type name(signature) description
    string 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.
    string regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT) Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns 'fb.' 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.

    参考文献:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

    相关文章

      网友评论

          本文标题:hive 匹配正则表达式

          本文链接:https://www.haomeiwen.com/subject/nfwgkctx.html