mysql> SELECT 'stab' REGEXP '.ta*b';
+-----------------------+
| 'stab' REGEXP '.ta*b' |
+-----------------------+
| 1 |
+-----------------------+
row in set (0.00 sec)
mysql> SELECT 'stb' REGEXP '.ta*b';
+----------------------+
| 'stb' REGEXP '.ta*b' |
+----------------------+
| 1 |
+----------------------+
mysql> SELECT '' REGEXP 'a*';
+----------------+
| '' REGEXP 'a*' |
+----------------+
| 1 |
+----------------+
1 row in set (0.00 sec)
a+
匹配1个或者多个a,但是不包括空字符
mysql> SELECT 'stab' REGEXP '.ta+b';
+-----------------------+
| 'stab' REGEXP '.ta+b' |
+-----------------------+
| 1 |
+-----------------------+
row in set (0.00 sec)
mysql> SELECT 'stb' REGEXP '.ta+b';
+----------------------+
| 'stb' REGEXP '.ta+b' |
+----------------------+
| 0 |
+----------------------+
row in set (0.00 sec)
a?
匹配0个或者1个a
mysql> SELECT 'stb' REGEXP '.ta?b';
+----------------------+
| 'stb' REGEXP '.ta?b' |
+----------------------+
| 1 |
+----------------------+
row in set (0.00 sec)
mysql> SELECT 'stab' REGEXP '.ta?b';
+-----------------------+
| 'stab' REGEXP '.ta?b' |
+-----------------------+
| 1 |
+-----------------------+
row in set (0.00 sec)
mysql> SELECT 'staab' REGEXP '.ta?b';
+------------------------+
| 'staab' REGEXP '.ta?b' |
+------------------------+
| 0 |
+------------------------+
row in set (0.00 sec)
a1|a2
匹配a1或者a2,
mysql> SELECT 'a' REGEXP 'a|b';
+------------------+
| 'a' REGEXP 'a|b' |
+------------------+
| 1 |
+------------------+
row in set (0.00 sec)
mysql> SELECT 'b' REGEXP 'a|b';
+------------------+
| 'b' REGEXP 'a|b' |
+------------------+
| 1 |
+------------------+
row in set (0.00 sec)
mysql> SELECT 'b' REGEXP '^(a|b)';
+---------------------+
| 'b' REGEXP '^(a|b)' |
+---------------------+
| 1 |
+---------------------+
row in set (0.00 sec)
mysql> SELECT 'a' REGEXP '^(a|b)';
+---------------------+
| 'a' REGEXP '^(a|b)' |
+---------------------+
| 1 |
+---------------------+
row in set (0.00 sec)
mysql> SELECT 'c' REGEXP '^(a|b)';
+---------------------+
| 'c' REGEXP '^(a|b)' |
+---------------------+
| 0 |
+---------------------+
row in set (0.00 sec)
注意:^符合只有在[]内才是取反的意思,在别的地方都是表示开始处匹配
a{m}
匹配m个a
mysql> SELECT 'auuuuc' REGEXP 'au{4}c';
+--------------------------+
| 'auuuuc' REGEXP 'au{4}c' |
+--------------------------+
| 1 |
+--------------------------+
row in set (0.00 sec)
mysql> SELECT 'auuuuc' REGEXP 'au{3}c';
+--------------------------+
| 'auuuuc' REGEXP 'au{3}c' |
+--------------------------+
| 0 |
+--------------------------+
row in set (0.00 sec)
a{m,}
匹配m个或者更多个a