title: MySQL REGEXP using Rails ActiveRecord
body: <p>This has been bugging me for a while now... I need to query a table of users and find those that have a double space in the name.
  I have multiple versions of SQL queries that work directly against the db, the simplest and more succinct being: </p>
  
  <pre><code>SELECT 'first  last' REGEXP '[[:space:]]{2}';
  </code></pre>
  
  <p>I can also make it work from rails using ruby REGEX:</p>
  
  <pre><code>User.pluck(:full_name).select {|n| n =~ /([[:alpha:]]*)[[:space:]]{2}/ }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>User.pluck(:full_name).select {|n| n =~ /\w+\s{2}/ }
  </code></pre>
  
  <p>I have been trying to use AR where in several ways, but I am not sure what I am missing. Maybe I need to escape something...
  I read a few times:
  <a href="http://dev.mysql.com/doc/refman/5.0/en/regexp.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/regexp.html</a></p>
  
  <p>I just don't see why it doesn't work</p>
  
  <pre><code>2] pry(main)&gt; User.where("'full_name' REGEXP ?", "[[:alpha:]]*[[:space:]]{2}").count
  =&gt; 0
  [3] pry(main)&gt; User.where("'full_name' REGEXP ?", '[[:alpha:]]*[[:space:]]{2}').count
  =&gt; 0
  [4] pry(main)&gt; User.where("'full_name' REGEXP ?", '[[:alpha:]]*[[:space:]]{2}').to_sql
  =&gt; "SELECT `users`.* FROM `users` WHERE ('full_name' REGEXP '[[:alpha:]]*[[:space:]]{2}')"
  [5] pry(main)&gt; User.where("'full_name' REGEXP ?", '[[:space:]]{2}')
  =&gt; []
  [6] pry(main)&gt; User.where("'full_name' REGEXP ?", '[[:blank:]]{2}')
  =&gt; []
  [7] pry(main)&gt; User.where("'full_name' RLIKE ?", '[[:blank:]]{2}')
  =&gt; []
  [8] pry(main)&gt; User.where("'full_name' RLIKE ?", '[[:blank:]]{2}').to_sql
  =&gt; "SELECT `users`.* FROM `users` WHERE ('full_name' RLIKE '[[:blank:]]{2}')"
  [9] pry(main)&gt; User.where("'full_name' RLIKE ?", '[[:blank:]]').count
  =&gt; 0
  [10] pry(main)&gt; User.where("'full_name' RLIKE ?", '[[:space:]]').count
  =&gt; 0
  [11] pry(main)&gt; User.where("'full_name' RLIKE ?", '.*[[:space:]].*').count
  =&gt; 0
  [12] pry(main)&gt; User.where("'full_name' RLIKE ?", '\[[:space:]\]').count
  =&gt; 0
  </code></pre>