Escaping parentheses in MySQL regex queries

Hello, I am currently trying to create a SQL query with regular expressions. However, I didn’t find any way to escape parentheses that are a part of the query.

SELECT * FROM tablename WHERE something REGEXP 'regulartext([0-9]+) \\(parenthesis'

When I try to execute this, I get the following error:
#1139 - Got error ‘parentheses not balanced’ from regexp”

My query will be a bit more complicated than the example above, but I can’t find a way to escape the parantheses - so an entry containing “regulartext8 (paranthesis” will be matched. How can I do that?

I’m a bit rusty with regular expressions but you might want to try making it a double backslash rather than just 1. i.e. \\ rather than \

That is just a guess.

Thanks a lot! It seems to work fine. That’s strange though, because adding \ before another \ usually escapes the \ so it’s just parsed as a regular backslash. :confused:

I think it gets parsed once by MySQL itself and then again by MySQL’s REGEX parser, if you see what I mean. So essentially it goes from





( (a literal open bracket)