title: PHP - How to search an associative array by matching the key against a regexp
body: <p>I am currently working on a small script to convert data coming from an external source. Depending on the content I need to map this data to something that makes sense to my application.</p>
  
  <p>A sample input could be:</p>
  
  <pre><code>$input = 'We need to buy paper towels.'
  </code></pre>
  
  <p>Currently I have the following approach:</p>
  
  <pre><code>// Setup an assoc_array what regexp match should be mapped to which itemId
  private $itemIdMap = [ '/paper\stowels/' =&gt; '3746473294' ];
  
  // Match the $input ($key) against the $map and return the first match
  private function getValueByRegexp($key, $map) {
    $match = preg_grep($key, $map);
    if (count($match) &gt; 0) {
      return $match[0];
    } else {
      return '';
    }
  }
  </code></pre>
  
  <p>This raises the following error on execution:</p>
  
  <blockquote>
    <p>Warning: preg_grep(): Delimiter must not be alphanumeric or backslash</p>
  </blockquote>
  
  <p>What am I doing wrong and how could this be solved?</p>