title: preg_replace Is it possible to replace everything in between two symbols?
body: <p>I've created a template system that replaces all variables starting and ending in '%%'. The problem is that preg replace sometimes replaces more than it should, here's an example:</p>
  
  <pre><code>&lt;?php
      $str  = "100% text %everythingheregone% after text";
      $repl = "test";
      $patt = "/\%([^\]]+)\%/"; 
      $res  = preg_replace($patt, "", $str);
      echo $res;
  ?&gt;
  </code></pre>
  
  <p>This outputs "100 after text", and it should output "100% text after text". Is there any solution to this? This is really bad because if there are CSS rules in the document, percentage signs are used and it ends up replacing all the document.</p>