Consider the following table :
mysql> select * from test;
+---------+
| col |
+---------+
| ^test$ |
| tes$()t |
| X$%[ |
| test$ |
| ^test |
| test |
| [ |
+---------+
7 rows in set (0.04 sec)
It contains valid and invalid patterns.
If I do :
mysql> select * from test where 'test' regexp col;
+--------+
| col |
+--------+
| ^test$ |
| test$ |
| ^test |
| test |
+--------+
4 rows in set (0.04 sec)
I get all rows with a pattern matching ‘test’, and all other rows (including invalid patterns) are just ignored.
Now, if I do an invalid request directly, I get a pattern syntax error :
mysql> select * from test where 'test' regexp '[';
ERROR 1139 (42000): Got error 'brackets ([ ]) not balanced' from regexp
Is there a way (without another table) to force MySQL to ignore those errors (will give an empty result for example) ?
Okey I found a working solution, that’s tricky but that work :
Replace ‘[‘ by your regexp pattern. May be useful if you allow your customers to use regexps.