溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

hive中正則表達(dá)式怎么用

發(fā)布時(shí)間:2021-12-10 11:52:42 來源:億速云 閱讀:344 作者:小新 欄目:大數(shù)據(jù)

小編給大家分享一下hive中正則表達(dá)式怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

 hive中的正則表達(dá)式還是很強(qiáng)大的。數(shù)據(jù)工作者平時(shí)也離不開正則表達(dá)式。對此,特意做了個(gè)hive正則表達(dá)式的小結(jié)。所有代碼都經(jīng)過親測,正常運(yùn)行。

2.regexp_extract

語法: regexp_extract(string subject, string pattern, int index) 
返回值: string 
說明:將字符串subject按照pattern正則表達(dá)式的規(guī)則拆分,返回index指定的字符。

hive> select regexp_extract('IloveYou','I(.*?)(You)',1) from test1 limit 1;
Total jobs = 1
。。。
Total MapReduce CPU Time Spent: 7 seconds 340 msec
ok
love
Time taken: 28.067 seconds, Fetched: 1 row(s)

hive> select regexp_extract('IloveYou','I(.*?)(You)',2) from test1 limit 1;
You
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',1) from test1 limit 1;
I
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',0) from test1 limit 1;
IloveYou

hive> select regexp_replace("IloveYou","You","") from test1 limit 1;
Ilove

<h3 id="3regexpreplace" font-weight:300;line-height:1.1;color:#3F3F3F;font-size:2.15em;white-space:normal;background-color:#FFFFFF;"> 3.regexp_replace

語法: regexp_replace(string A, string B, string C) 
返回值: string 
說明:將字符串A中的符合java正則表達(dá)式B的部分替換為C。注意,在有些情況下要使用轉(zhuǎn)義字符,類似oracle中的regexp_replace函數(shù)。


hive> select regexp_replace("IloveYou","You","") from test1 limit 1;
Ilove
hive> select regexp_replace("IloveYou","You","lili") from test1 limit 1;
Ilovelili

以上是“hive中正則表達(dá)式怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI