标签:pad 序号 font order add pass 16px 知识点 reg
知识点九:MySQL中使用正则表达式(44)
(1):REGEXP‘匹配方式’:
(2):常用匹配方式:
模式字符 |
|
^ |
匹配字符开始的部分 |
$ |
匹配字符串结尾的部分 |
. |
代表字符串中的任意一个字符,包括回车和换行 |
[字符集和] |
匹配字符集和中的任意一个字符 |
[^字符集和] |
匹配除了字符集合以外的任何一个字符 |
S1|S2|S3 |
匹配S1,S2,S3中任意一个字符串 |
* |
代表0和1个或者多个其前的字符 |
+ |
代表1个或者多个其前的字符 |
String{N} |
字符串出现N次 |
字符串{M,N} |
字符串至少出现M次,最多出现N次 |
1 -- ^匹配字符开始的部分 2 -- 查询用户名以t开始的用户 3 SELECT * FROM cms_user WHERE username REGEXP ‘^t‘; 4 5 -- $匹配字符串结尾的部分 6 7 SELECT * FROM cms_user WHERE username REGEXP ‘g$‘; 8 9 10 -- .代表任意字符 11 12 SELECT * FROM cms_user WHERE username REGEXP ‘.‘; 13 14 SELECT * FROM cms_user WHERE username REGEXP ‘r..g‘; 15 16 SELECT * FROM cms_user WHERE username LIKE ‘r__g‘; 17 18 -- [字符集合] [lto] 19 20 SELECT * FROM cms_user WHERE username REGEXP ‘[lto]‘; 21 22 -- [^字符集合] 除了字符集合中的内容 23 SELECT * FROM cms_user WHERE username REGEXP ‘[^lto]‘; 24 25 SELECT * FROM cms_user WHERE username REGEXP ‘[^l]‘; 26 27 INSERT cms_user(username,password,regTime,proId) 28 VALUES(‘lll‘,‘lll‘,138212349,2), 29 (‘ttt‘,‘lll‘,138212349,2), 30 (‘ooo‘,‘lll‘,138212349,2); 31 32 SELECT * FROM cms_user WHERE username REGEXP ‘[a-k]‘; 33 34 SELECT * FROM cms_user WHERE username REGEXP ‘[^a-m]‘; 35 36 SELECT * FROM cms_user WHERE username REGEXP ‘ng|qu‘; 37 38 SELECT * FROM cms_user WHERE username REGEXP ‘ng|qu|te‘; 39 40 SELECT * FROM cms_user WHERE username REGEXP ‘que*‘; 41 42 43 SELECT * FROM cms_user WHERE username REGEXP ‘t+‘; 44 45 SELECT * FROM cms_user WHERE username REGEXP ‘que+‘; 46 47 SELECT * FROM cms_user WHERE username REGEXP ‘que{2}‘; 48 49 SELECT * FROM cms_user WHERE username REGEXP ‘que{3}‘; 50 51 SELECT * FROM cms_user WHERE username REGEXP ‘que{1,3}‘;
MYSQL初级学习笔记七:MySQL中使用正则表达式!(视频序号:初级_44)
标签:pad 序号 font order add pass 16px 知识点 reg
原文地址:https://www.cnblogs.com/darwinli/p/9012916.html