MySQL Regexp with square brackets
I am trying to match strings such as "[sometext <someothertext>]" (ie left square bracket, text, left angle bracket, text, right angle bracket, right angle bracket) inside mySQL column. I originally used the following query (note that since regular expression queries are executed twice in mySQL, you should use two backslashes, in which you usually use one):
SELECT * FROM message WHERE msgtext REGEXP '\\[(.+)?<(.+)?>\\]'
There were no errors in this request, but they returned to me what I did not want. Instead of (. +) I would like [^ \]] (everything except the rectangular bracket would match). When I changed the request, I received the following error: "Error operand repeat-operation operand error is invalid" from regexp "
After reading the mySQL documentation here , it indicates the symbol "Include Literal", it should immediately follow the opening bracket [. "Since I want" ^ \] "instead of"] ", is this possible since the bracket cannot be the first character after opening the bracket? Below are some of the queries I tried that get the same error as above :
SELECT * FROM message WHERE msgtext REGEXP '\\[([^\\]]+?)<([^\\]]+?)>\\]'
SELECT * FROM message WHERE msgtext REGEXP '\\[[^\\]]+?<[^\\]]+?>\\]'
SELECT * FROM message WHERE msgtext REGEXP '\\[[^[.right-square-bracket.]]]+?<[^[.right-square-bracket.]]]+?>\\]'
UPDATE:
The following query is executed without errors, but does not return any rows, although I know that there are columns that match what I'm looking for (based on my original query at the top):
SELECT * FROM message WHERE msgtext REGEXP '\\[([^\\]]+)?<([^\\]]+)?>\\]'