title: Mysql regex error #1139 using literal -
body: <p>I tried running this query:</p>
  
  <pre><code>SELECT column FROM table WHERE column REGEXP '[^A-Za-z\-\']'
  </code></pre>
  
  <p>but this returns </p>
  
  <blockquote>
    <p>#1139 - Got error 'invalid character range' from regexp</p>
  </blockquote>
  
  <p>which seems to me like the <code>-</code> in the character class is not being escaped, and instead read as an invalid range. Is there some other way that it's suppose to be escaped for mysql to be the literal <code>-</code>?</p>
  
  <p>This regex works as expected outside of mysql, <a href="https://regex101.com/r/wE8vY5/1" rel="noreferrer">https://regex101.com/r/wE8vY5/1</a>.</p>
  
  <p>I came up with an alternative to that regex which is</p>
  
  <pre><code>SELECT column FROM table WHERE column NOT REGEXP '([:alpha:]|-|\')'
  </code></pre>
  
  <p>so the question isn't how do I get this to work. The question is why doesn't the first regex work?</p>
  
  <p>Here's a SQL fiddle of the issue, <a href="http://sqlfiddle.com/#!9/f8a006/1" rel="noreferrer">http://sqlfiddle.com/#!9/f8a006/1</a>.</p>
  
  <p>Also, there is no language being used here, query is being run at DB level.</p>
  
  <p>Regex in PHP: <a href="http://sandbox.onlinephpfunctions.com/code/10f5fe2939bdbbbebcc986c171a97c0d63d06e55" rel="noreferrer">http://sandbox.onlinephpfunctions.com/code/10f5fe2939bdbbbebcc986c171a97c0d63d06e55</a></p>
  
  <p>Regex in JS: <a href="https://jsfiddle.net/6ay4zmrb/" rel="noreferrer">https://jsfiddle.net/6ay4zmrb/</a></p>