title: Using preg_replace() for suffix and postfix amid other text
body: <p>I've been trying to make a mini markup parser similar to Markdown in PHP. The input looks like this:</p>
  
  <blockquote>
    <p>Some text **that is bold!** and some other text</p>
  </blockquote>
  
  <p>into</p>
  
  <blockquote>
    <p>Some text &lt;b&gt;that is bold!&lt;/b&gt; and some other text</p>
  </blockquote>
  
  <p>I've found countless resources on how to replace a chunk of text with another, but only one that actually replaces suffix and postfix: <a href="https://stackoverflow.com/a/2917064/2194007">this answer</a>. After messing around with it a bit it looks like this:</p>
  
  <pre><code>$s=preg_quote("**");
  
  $in = preg_replace(
      array('%'.$s.'-%', '%-%', '%'.$s.'%'), 
      array('&lt;b&gt;','_','&lt;/b&gt;'),
      $in);
  </code></pre>
  
  <p>Earlier attempts are equally clumsy. It's obvious I don't really get regex or that engine's syntax so I'm at a loss. The alternative is to hack the string into pieces and add/remove what I need, but regex seems much more elegant. Any ideas?</p>
  
  <hr>
  
  <p>Fix: Earlier I wrote <code>$s=preg_quote($s)</code> by mistake, corrected to <code>$s=preg_quote("**")</code></p>