基本形式
屬性名 regexp ‘匹配方式'
1.匹配字符開始的部分
select * from info where name regexp '^L';
2.匹配字符結(jié)束的部分
select * from info where name regexp 'c$';
3.匹配字符串中的任意一個字符,包括回車和換行
eg1: 從info表name字段中查詢以L開頭y結(jié)尾中間有兩個任意字符的記錄
select * from info where name regexp '^L..y$';
4.[字符集合]匹配字符集合中的任意字符
eg1: 從info表name字段中查詢包含c、e、o三個字母中任意一個的記錄
select * from info where name regexp '[ceo]';
eg2: 從info表name字段中查詢包含數(shù)字的記錄
select * from info where name regexp '[0-9]';
eg3: 從info表name字段中查詢包含數(shù)字或a、b、c三個字母中任意一個的記錄
select * from info where name regexp '[0-9a-c]';
5.[^字符集合]匹配除了字符集合外的任意字符
eg1: 從info表name字段中查詢包含a-w字母和數(shù)字以外字符的記錄
select * from info where name regexp '[^a-w0-9]';
6.s1|s2|s3 匹配s1s2s3中的任意一個
eg1: 從info表name字段中查詢包含'ic'的記錄
select * from info where name regexp 'ic';
eg2: 從info表name字段中查詢包含ic、uc、ab三個字符串中任意一個的記錄
select * from info where name regexp 'ic|uc|ab';
7.* 代表多個該字符前的字符,包括0個或1個
eg1: 從info表name字段中查詢c之前出現(xiàn)過a的記錄
select * from info where name regexp 'a*c';
8.+ 代表多個該字符前的字符,包括1個
eg1: 從info表name字段中查詢c之前出現(xiàn)過a的記錄
select * from info where name regexp 'a+c';(注意比較結(jié)果!)
9.字符串{N} 字符串出現(xiàn)N次
eg1: 從info表name字段中查詢出現(xiàn)過a3次的記錄
select * from info where name regexp 'a{3}';
10.字符串{M,N}字符串最少出現(xiàn)M次,最多出現(xiàn)N次
eg1: 從info表name字段中查詢ab出現(xiàn)最少1次最多3次的記錄
select * from info where name regexp 'ab{1,3}';