Mysql正则表达式匹配字符串开头或结尾的括号字符

时间:2016-06-27 15:17:53

标签: mysql regex

我想匹配('开头的字符,或')'字符串末尾的字符。我尝试过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)

1 个答案:

答案 0 :(得分:0)

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

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