Note that there are some explanatory texts on larger screens.

plurals
  1. POmySQL Regexp with square brackets
    primarykey
    data
    text
    <p>I am trying to match strings like '[sometext&lt;someothertext&gt;]' (i.e., left square bracket, text, left angle bracket, text, right angle bracket, right square bracket) within a column in mySQL. Originally I used the following query (notice that since regex queries are escaped twice in mySQL, you must use two backslashes where you would normally use one):</p> <pre><code>SELECT * FROM message WHERE msgtext REGEXP '\\[(.+)?&lt;(.+)?&gt;\\]' </code></pre> <p>This query received no errors, but it returned things I didn't want. Instead of the (.+), I wanted [^\]] (match everything except a right square bracket). When I changed the query, I got the following error: "Got error 'repetition-operator operand invalid' from regexp"</p> <p>After reading through the mySQL documentation <a href="http://dev.mysql.com/doc/refman/5.1/en/regexp.html" rel="nofollow noreferrer">here</a>, it states "To include a literal ] character, it must immediately follow the opening bracket [." Since I want "^\]" instead of "]", is this even possible since the bracket can't be the first character after the opening bracket? Below are some of the queries I have tried which get the same error listed above:</p> <pre><code>SELECT * FROM message WHERE msgtext REGEXP '\\[([^\\]]+?)&lt;([^\\]]+?)&gt;\\]' SELECT * FROM message WHERE msgtext REGEXP '\\[[^\\]]+?&lt;[^\\]]+?&gt;\\]' SELECT * FROM message WHERE msgtext REGEXP '\\[[^[.right-square-bracket.]]]+?&lt;[^[.right-square-bracket.]]]+?&gt;\\]' </code></pre> <p>UPDATE:</p> <p>The following query runs without errors, but does not return any rows even though I know there are columns which match what I am looking for (based on my original query at the top):</p> <pre><code>SELECT * FROM message WHERE msgtext REGEXP '\\[([^\\]]+)?&lt;([^\\]]+)?&gt;\\]' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload