]" (ie left square bracket, text, left angle b...">

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 '\\[([^\\]]+)?<([^\\]]+)?>\\]'
+3
source share
2 answers

This works for me:

SELECT '[sometext<someothertext>]' REGEXP '\\[([^[.right-square-bracket.]]+)?<([^[.right-square-bracket.]]+)?>\\]$';
+6
source

Firefox/JS, . , MySQL , ... , .

, : http://mysqludf.com/lib_mysqludf_preg/

, * +? .

* 0 ()
+? 1 ()

0

Source: https://habr.com/ru/post/1709868/


All Articles