title: Mysql regex using multiple rules to match string
body: <p>I've got a table as follows: (transactions_filter):</p>
  
  <pre>
  +----+------------------------------+------------+--------------------------+
  | ID | ContactName                  | account_id | Expression               |
  +----+------------------------------+------------+--------------------------+
  |  1 | Salaries & Wages             |    6123372 | SH\-01\-[0-9]*?\-477\-0  |
  |  2 | Salaries & Wages             |    6123372 | SH\-01\-00000001\-550\-0 |
  |  3 | Salaries & Wages             |    6123372 | SH\-01\-00000001\-551\-0 |
  </pre>
  
  <p>And then my transactions looks as follows: (accounts)</p>
  
  <pre>
  +---------+------------------------------------+-------------+--------+---------+-------------+--------------------+-------------+-------------+-------------+------------------+---------------------+---------------------+
  | ID      | Name                               | category_id | Active | Balance | Description | UnallocatedAccount | IsTaxLocked | AccountType | HasActivity | DefaultTaxTypeId | Modified            | Created             |
  +---------+------------------------------------+-------------+--------+---------+-------------+--------------------+-------------+-------------+-------------+------------------+---------------------+---------------------+
  | 6123359 | Accounting Fees                    |           4 |      1 |    0.00 |             |                  0 |           0 |           1 |           0 |          1509579 | 2016-03-19 15:06:34 | 2016-03-19 15:06:34 |
  | 6123360 | Advertising                        |           4 |      1 |    0.00 |             |                  0 |           0 |           1 |           0 |          1509579 | 2016-03-19 15:06:34 | 2016-03-19 15:06:34 |
  | 6123357 | Bad Debts Recovered                |           3 |      1 |    0.00 |             |                  0 |           0 |           1 |           0 |          1509579 | 2016-03-19 15:06:34 | 2016-03-19 15:06:34 |
  </pre>
  
  <p>And my transactions table looks as follows:</p>
  
  <pre>
  +-------+------------+------------+-------------------------------------------------------------+-----------------------------+----------+------------+---------------+---------------------+---------------------+
  | id    | foreign_id | date       | description                                                 | short_description           | amount   | balance    | function_code | created_at          | updated_at          |
  +-------+------------+------------+-------------------------------------------------------------+-----------------------------+----------+------------+---------------+---------------------+---------------------+
  | 38322 |            | 2015-12-01 | MONTHLY ACC FEE      HEADOFFICE                             |                             |   -59.50 | -181792.19 | SERM          | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38323 |            | 2015-12-01 | TRANSACTION CHARGE   HEADOFFICE                             |                             |  -198.75 | -181990.94 | TRNC          | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38324 |            | 2015-12-01 | CASH DEPOSIT FEE     HEADOFFICE                             |                             | -2638.01 | -184628.95 | CSHC          | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38325 |            | 2015-12-01 | OD: LEDGER FEE       HEADOFFICE                             |                             |   -40.00 | -184668.95 | FACF          | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38326 |            | 2015-12-01 | DEBIT INTEREST       HEADOFFICE                             |                             | -2390.35 | -187059.30 | INDR          | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38327 |            | 2015-12-01 | STOP ORDER FROM      SETTLEMENT ABSA BANK 123.com           | ABSA BANK 123.com           |    30.00 | -187029.30 | SIC           | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38328 |            | 2015-12-01 | STOP ORDER FROM      SETTLEMENT ABSA BANK acc8469           | ABSA BANK acc8469           |    29.90 | -186999.40 | SIC           | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38329 |            | 2015-12-01 | STOP ORDER FROM      SETTLEMENT ABSA BANK 321.co.za         | ABSA BANK loxizea.co.za     |    29.99 | -186969.41 | SIC           | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38330 |            | 2015-12-01 | STOP ORDER FROM      SETTLEMENT ABSA BANK cceyc             | ABSA BANK cceyc             |    30.00 | -186939.41 | SIC           | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  | 38331 |            | 2015-12-01 | STOP ORDER FROM      SETTLEMENT ABSA BANK 178444 123        | ABSA BANK 178444 123        |    35.00 | -186904.41 | SIC           | 2016-03-16 14:03:27 | 2016-03-16 14:03:27 |
  +-------+------------+------------+-------------------------------------------------------------+-----------------------------+----------+------------+---------------+---------------------+---------------------+
  </pre>
  
  <p>Now how would I be able to match the transactions to my filters without looping through each filter as follows:</p>
  
  <pre><code>    $filters = \App\Models\Transaction\Filter::All();   
      $transactions = \App\Models\Transaction::All();
  
      $data = [];
      foreach($transactions as $transaction)
      {
          foreach($filters as $filter)
          {
              if(preg_match("/" . $filter-&gt;Expression . "/", $transaction-&gt;description))
              {
                  $data[] = [
                      'date' =&gt; $transaction-&gt;date,
                      'ContactName' =&gt; $filter-&gt;ContactName,
                      'account_id' =&gt; $filter-&gt;account_id,
                  ];
              }
          }
      }
  
      dd($data);
  </code></pre>