我想在字符串的开头匹配'('字符,或')'字符。我尝试了theese(字符串的开头),但没有任何效果:

mysql> SELECT '(aaa' REGEXP '[[:<:]]\\(aaa';
+-------------------------------+
| '(aaa' REGEXP '[[:<:]]\\(aaa' |
+-------------------------------+
|                             0 |
+-------------------------------+
1 row in set (0.00 sec)

mysql> SELECT '(aaa' REGEXP '[[:<:]][(]aaa';
+-------------------------------+
| '(aaa' REGEXP '[[:<:]][(]aaa' |
+-------------------------------+
|                             0 |
+-------------------------------+
1 row in set (0.00 sec)

最佳答案

我认为您不需要在这里使用正则表达式,因为LIKE运算符应该足够了:

SELECT *
FROM yourTable
WHERE col LIKE '(%' OR col LIKE '%)'

07-24 09:37
查看更多