mysql簡單的Regex查詢

來源:互聯網
上載者:User

標籤:正則   運算式   mysql   

Regex是為複雜搜尋指定模式的強大方式。

MySQL採用Henry Spencer的Regex實施,其目標是符合POSIX 1003.2。

匹配以弄個數字開頭的字串

SELECT * FROM `gms_customer` where mobile REGEXP ‘^[0-9]‘;


匹配包含-的字串,有點類似 like %-%

特殊字元一般使用  \\-  \\.  \\為前置,進行轉移的作用

select * from gms_customer where mobile REGEXP ‘\\-‘;


匹配以 數字 結尾的字串

select * from gms_customer where mobile REGEXP ‘[0-9]$‘;


匹配 無 或者 空  有點類似  name = ‘無‘ or name=‘‘

select * from gms_customer where name REGEXP ‘無|‘‘‘;


匹配包含2 或者 6  或者 3 的字串

select * from gms_customer where customer_id REGEXP ‘[263]‘;


匹配字元:

[:a;num:]    任意字母和數字(同 [a-zA-Z0-9])

[:alpha:]    任一字元(同 [a-zA-Z])

[:blank:]    空格和製表(同 [\\t])

[:cntrl:]    ASCII控制字元(ASCII 0到31和127)

[:digit:]    任一數字(同[0-9])

[:graph:]    與["print:] 相同,但不包括空格

[:lower:]    任意小寫字線(同 [a-z])

[:print:]    任意可列印字元

[:punct:]    既不在 [:alnum:] 又不在 [:cntrl:] 中的任一字元

[space:]     包括空格在內的任意空白字元(同 [\\f\\n\\t\\r\\v])

[:upper:]    任意大小字母(同 [A-Z])

[:xdigit:]   任意十六進位數字(同 [a-fA-F0-9])


定位器:

^        文本的開始

$        文本的末尾

[[:<:]]  詞的開始

[[:>:]]  詞的結尾



Regex基礎知識可以參考:    Regex30分鐘入門教程

http://deerchao.net/tutorials/regex/regex-1.htm

本文出自 “追夢” 部落格,請務必保留此出處http://dreameng.blog.51cto.com/1187899/1588101

mysql簡單的Regex查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.