如果 expr
字符串與正則表達式 pat
不匹配,MySQL 的 NOT REGEXP
運算符將返回 1。如果有匹配則返回 0。
用法
SELECT expr NOT REGEXP pat;
1. expr
| string
我們與正則表達式模式匹配的字符串。
2. pat
| regular expression
用於匹配的正則表達式模式。
例子
考慮下表有關一些學生的信息:
student_id |
名稱 |
名字 |
day_enrolled |
年齡 |
用戶名 |
---|---|---|---|---|---|
1 |
Sky |
Towner |
2015-12-03 |
17 |
stowner1 |
2 |
Ben |
Davis |
2016-04-20 |
19 |
bdavis2 |
3 |
Travis |
Apple |
2018-08-14 |
18 |
tapple3 |
4 |
Arthur |
David |
2016-04-01 |
16 |
adavid4 |
5 |
Benjamin |
Town |
2014-01-01 |
17 |
btown5 |
可以使用此處的代碼創建上述示例表。
基本用法
要檢查學生姓氏是否與正則表達式模式 '[ae]'
不匹配:
SELECT lname, lname NOT REGEXP '[ae]'
FROM students;
+--------+-------------------------+
| lname | lname NOT REGEXP '[ae]' |
+--------+-------------------------+
| Towner | 0 |
| Davis | 0 |
| Apple | 0 |
| David | 0 |
| Town | 1 |
+--------+-------------------------+
隻有 'Town'
返回 1,因為它不包含 'a'
或 'e'
。
相關用法
- MySQL NOT IN用法及代碼示例
- MySQL NOT LIKE用法及代碼示例
- MySQL NOT BETWEEN用法及代碼示例
- MySQL NOT用法及代碼示例
- MySQL NOW()用法及代碼示例
- MySQL NOW方法用法及代碼示例
- MySQL NULLIF( )用法及代碼示例
- MySQL ROUND()用法及代碼示例
- MySQL REPEAT()用法及代碼示例
- MySQL POWER()用法及代碼示例
- MySQL LEAD() and LAG()用法及代碼示例
- MySQL IS_IPV4()用法及代碼示例
- MySQL RADIANS方法用法及代碼示例
- MySQL VARIANCE方法用法及代碼示例
- MySQL WEEK()用法及代碼示例
- MySQL TIME_FORMAT方法用法及代碼示例
- MySQL CURTIME()用法及代碼示例
- MySQL weekofyear()用法及代碼示例
- MySQL Convert()用法及代碼示例
- MySQL IS NOT用法及代碼示例
- MySQL FROM_BASE64()用法及代碼示例
- MySQL LEFT方法用法及代碼示例
- MySQL UCASE方法用法及代碼示例
- MySQL PI()用法及代碼示例
- MySQL CONCAT()用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 MySQL | NOT REGEXP。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。