Oralce中regex_like和hive的regexp對應
LIKE
語法1: A LIKE B
語法2: LIKE(A, B)
操作類型: strings
返回類型: boolean或null
描述: 如果字符串A或者字符串B為NULL,則返回NULL;如果字符串A符合表達式B的正則語法,則為TRUE;否則為FALSE。B中字符"_"表示任意單個字符,而字符"%"表示任意數量的字符。
hive> select 'football' like '%ba'; OK false hive> select 'football' like '%ba%'; OK true hive> select 'football' like '__otba%'; OK true hive> select like('football', '__otba%'); OK true
RLIKE
語法1: A RLIKE B
語法2: RLIKE(A, B)
操作類型: strings
返回類型: boolean或null
描述: 如果字符串A或者字符串B為NULL,則返回NULL;如果字符串A符合JAVA正則表達式B的正則語法,則為TRUE;否則為FALSE。
hive> select 'football' rlike 'ba'; OK true hive> select 'football' rlike '^footba'; OK true hive> select rlike('football', 'ba'); OK true
Java正則:
"." 任意單個字符
"*" 匹配前面的字符0次或多次
"+" 匹配前面的字符1次或多次
"?" 匹配前面的字符0次或1次
"\d" 等於 [0-9],使用的時候寫成'\d'
"\D" 等於 [^0-9],使用的時候寫成'\D'
hive> select 'does' rlike 'do(es)?'; OK true hive> select '\\'; OK \ hive> select '2314' rlike '\\d+'; OK true
REGEXP
語法1: A REGEXP B 語法2: REGEXP(A, B) 操作類型: strings 返回類型: boolean或null 描述: 功能與RLIKE相同 hive> select 'football' regexp 'ba'; OK true hive> select 'football' regexp '^footba'; OK true hive> select regexp('football', 'ba'); OK true 語法: regexp_replace(string A, string B, string C) 操作類型: strings 返回值: string 說明: 將字符串A中的符合java正則表達式B的部分替換為C。 hive> select regexp_replace('h234ney', '\\d+', 'o'); OK honey
REGEXP_REPLACE
語法: regexp_replace(string A, string B, string C)
操作類型: strings
返回值: string
說明: 將字符串A中的符合java正則表達式B的部分替換為C。
hive> select regexp_replace('h234ney', '\\d+', 'o');
OK
honey
REGEXP_EXTRACT
語法: regexp_extract(string A, string pattern, int index)
返回值: string
說明:將字符串A按照pattern正則表達式的規則拆分,返回index指定的字符,index從1開始計。
hive> select regexp_extract('honeymoon', 'hon(.*?)(moon)', 0); OK honeymoon hive> select regexp_extract('honeymoon', 'hon(.*?)(moon)', 1); OK ey hive> select regexp_extract('honeymoon', 'hon(.*?)(moon)', 2); OK moon