title: Pass regex special characters through web form to PHP regex
body: <p>I have a web form that does a search replace function.</p>
  
  <p>The form input is passed through <code>preg_quote</code>. That's been fine, until now.</p>
  
  <p>Now I want to allow users to input the <code>*</code> (asterisk) wildcard character. <code>preg_quote</code> escapes it. How can I allow it through and properly apply it?</p>
  
  <pre><code>$find = ',*'; // I want to match a comma and all characters after the comma
  $replace = ''; // replace with empty string
                      $find = preg_quote($find_replace[0],'~'); // $find == ',\*';. I want * to remain unescaped. Is replacing "\*" with "*" the best way?
                      if(strpos($find,'\\*') !== false) { // UPDATE: I tried that, and it does work.
                      // $find == ',\*'
                      $find = str_replace('\\*','*',$find);
                      // $find == ',*' -- seems like it should work but doesn't               
                  }
  
                      $value = trim(preg_replace('~' . $find . '~i',$replace,$value));
  </code></pre>
  
  <p>EDIT:
  I added in code above that strips out the escaping slash before the <code>*</code>. It is working.</p>
  
  <p>With <code>$value = 'Hey, hey, hey, hey'</code> I end up with '<code>Hey hey hey hey</code>'.
  All the commas are removed, as expected with the regex pattern <code>,*</code> (greedy matching?).</p>
  
  <p>Note, in my code I'll be using <code>$find = str_replace('\\*','.*',$find)</code> or <code>$find = str_replace('\\*','[\s\S]*',$find)</code>to replicate Microsoft Excel Find/Replace functionality.</p>