正则表达式查询
查询特定字符或字符串开头的记录
字符‘^’匹配以特定字符或字符串开头的文本
1.查询以x开头的记录
mysql> SELECT *
-> FROM fruits
-> WHERE f_name REGEXP '^x';
+------+------+---------+---------+
| f_id | s_id | f_name | f_price |
+------+------+---------+---------+
| b5 | 107 | xxxx | 3.60 |
| m2 | 105 | xbabay | 2.60 |
| t4 | 107 | xbababa | 3.60 |
+------+------+---------+---------+
3 rows in set (0.00 sec)
2查询以xx开头的记录
mysql> SELECT *
-> FROM fruits
-> WHERE f_name REGEXP '^xx';
+------+------+--------+---------+
| f_id | s_id | f_name | f_price |
+------+------+--------+---------+
| b5 | 107 | xxxx | 3.60 |
+------+------+--------+---------+
1 row in set (0.00 sec)
查询特定字符或字符串结尾的记录
字符$匹配以特定字符或字符串结尾的文本
1.查询以e结尾的记录
mysql> SELECT *
-> FROM fruits
-> WHERE f_name REGEXP 'e$';
+------+------+--------+---------+
| f_id | s_id | f_name | f_price |
+------+------+--------+---------+
| a1 | 101 | apple | 5.20 |
| bs1 | 102 | orange | 11.20 |
| t2 |