title: How to use REGEXP in MYSQL to match dates IN array?
body: <p>I am trying to match the year from the publication_date of a table in a lot of years. I am using laravel (PHP).</p>
  
  <p>I have written something like:</p>
  
  <pre><code>if($this-&gt;request-&gt;has('publication_years')){
      $years = implode('-[0-9]{2}-[0-9]{2}|', explode(',', $this-&gt;request-&gt;get('publication_years'))) . '-[0-9]{2}-[0-9]{2}';
  
      $model = $model-&gt;whereExists(function ($query) use ($years)
      {
          $query-&gt;select(DB::raw(1))
              -&gt;from('patent')
              -&gt;whereRaw('patent.id = document.documentable_id')
              -&gt;whereRaw('document.documentable_type = "patent"')
              -&gt;whereRaw('(patent.publication_date REGEXP (' . $years . '))');
      });
  }
  </code></pre>
  
  <p>The years come like <code>?publication_years=2015,2016</code>. I explode them use the <code>,</code> delimiter and then implode them to make the REGEXP pattern in a way it matches the date. The dump of the years after this is like <code>2015-[0-9]{2}-[0-9]{2}|2016-[0-9]{2}-[0-9]{2}</code>.</p>
  
  <p>This works at <a href="http://regexr.com/" rel="nofollow">http://regexr.com/</a> but I am still getting error so I am guessing there some other syntax for MYSQL. The error that I see is:</p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[0-9]{2}-[0-9]{2}|2016-[0-9]{2}-[0-9]{2})))' at line 1 (SQL: select count(*) as aggregate from `document` where exists (select * from `folder` where `document`.`folder_id` = `folder`.`id` and (exists (select * from `user` inner join `accessible_by_user` on `user`.`id` = `accessible_by_user`.`user_id` where `accessible_by_user`.`accessible_id` = `folder`.`id` and `accessible_by_user`.`accessible_type` = folder and `user_id` = 1) or exists (select * from `role` inner join `accessible_by_role` on `role`.`id` = `accessible_by_role`.`role_id` where `accessible_by_role`.`accessible_id` = `folder`.`id` and `accessible_by_role`.`accessible_type` = folder and `role_id` in (1)))) and exists (select 1 from `patent` where patent.id = document.documentable_id and document.documentable_type = "patent" and (patent.publication_date REGEXP (2015-[0-9]{2}-[0-9]{2}|2016-[0-9]{2}-[0-9]{2}))))
  </code></pre>
  
  <p>What am I doing wrong? How can I correct this?</p>