MySQL正则表达式 regexp
基本用法
‘^’ / '$'从开头/结尾匹配符号
select code from bk_material where code regexp '^W$';
检索以W开头以W结尾的数据,那么就是只含W的数据。
'.'匹配除\n以外的任一个字符
select code from bk_material where code regexp '^.W';
匹配第二个字符是W的数据
'[…]'匹配括号里面包含的任一个字符的数据
select code from bk_material where code regexp '^[a-zA-Z]';
匹配第一个字符是英文的数据
‘[^…]’ 匹配不包含括号里字符或模式的数据
select code from bk_material where code regexp '^.W';'
匹配首字母不为W的字符串
'p1|p2|p3’匹配p1或者p2或者p3模式
select Name from bk_material where name regexp '^a|w|p';'
匹配首字母是a,w,p的字符串