您好,登錄后才能下訂單哦!
本文主要給大家介紹MySQL8.0目前支持哪幾種正則表達(dá)式函數(shù),文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對性,對大家的參考意義還是比較大的,下面跟筆者一起了解下MySQL8.0目前支持哪幾種正則表達(dá)式函數(shù)吧。
Name | Description |
---|---|
NOT REGEXP | Negation of REGEXP |
REGEXP | Whether string matches regular expression |
REGEXP_INSTR() | Starting index of substring matching regular expression |
REGEXP_LIKE() | Whether string matches regular expression |
REGEXP_REPLACE() | Replace substrings matching regular expression |
REGEXP_SUBSTR() | Return substring matching regular expression |
RLIKE | Whether string matches regular expression |
regexp、rlike、regexp_like()三者功能相同,只是寫法不同
not regexp是否定形式
mysql> select 'abc' regexp '^a'; +-------------------+ | 'abc' regexp '^a' | +-------------------+ | 1 | +-------------------+ 1 row in set (0.00 sec) mysql> select 'abc' rlike '^a'; +------------------+ | 'abc' rlike '^a' | +------------------+ | 1 | +------------------+ 1 row in set (0.00 sec) mysql> select regexp_like('abc','^a'); +-------------------------+ | regexp_like('abc','^a') | +-------------------------+ | 1 | +-------------------------+ 1 row in set (0.00 sec) mysql> select 'abc' not regexp '^a'; +-----------------------+ | 'abc' not regexp '^a' | +-----------------------+ | 0 | +-----------------------+ 1 row in set (0.00 sec) mysql> select not regexp_like('abc','^a'); +-----------------------------+ | not regexp_like('abc','^a') | +-----------------------------+ | 0 | +-----------------------------+ 1 row in set (0.00 sec)
regexp_replace()替代函數(shù)
mysql> select regexp_replace('a1,b2,c3','[a-z]{1}','b'); +-------------------------------------------+ | regexp_replace('a1,b2,c3','[a-z]{1}','b') | +-------------------------------------------+ | b1,b2,b3 | +-------------------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_replace('aaa,b2,c3','[a-z]{2}','d'); +--------------------------------------------+ | regexp_replace('aaa,b2,c3','[a-z]{2}','d') | +--------------------------------------------+ | da,b2,c3 | +--------------------------------------------+ 1 row in set (0.00 sec)
regexp_substr() 截斷字符串
mysql> select regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,1); +-----------------------------------------------------+ | regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,1) | +-----------------------------------------------------+ | a1 | +-----------------------------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,2); +-----------------------------------------------------+ | regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,2) | +-----------------------------------------------------+ | b1 | +-----------------------------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,3); +-----------------------------------------------------+ | regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,3) | +-----------------------------------------------------+ | c1 | +-----------------------------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,4); +-----------------------------------------------------+ | regexp_substr('a1,b1,c1,ddds','[a-z 0-9]{1,9}',1,4) | +-----------------------------------------------------+ | ddds | +-----------------------------------------------------+ 1 row in set (0.00 sec)
regexp_instr() 返回匹配的字符串開始位置index.
mysql> select regexp_instr('dogcatdog','dog',1); +-----------------------------------+ | regexp_instr('dogcatdog','dog',1) | +-----------------------------------+ | 1 | +-----------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_instr('dogcatdog','dog',2); +-----------------------------------+ | regexp_instr('dogcatdog','dog',2) | +-----------------------------------+ | 7 | +-----------------------------------+ 1 row in set (0.00 sec) mysql> select regexp_instr('a aa aaa aaaa','a{3}',1); +----------------------------------------+ | regexp_instr('a aa aaa aaaa','a{3}',1) | +----------------------------------------+ | 6 | +----------------------------------------+ 1 row in set (0.00 sec)
看完以上關(guān)于MySQL8.0目前支持哪幾種正則表達(dá)式函數(shù),很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。