title: How to use backreferences in PHP
body: <p>I want to add a character to the end of each file extension found in a body of text using preg_replace().</p>
  
  <p>Here is some sample text:</p>
  
  <pre><code>$string='http://www.mysite.com/expert/images/imageone.jpghttp://www.mysite.com/expert/images/imagetwo.jpg';
  </code></pre>
  
  <p>This search &amp; replace works fine in TextWrangler, appending a semi colon to file extensions:</p>
  
  <pre><code>(\.(jpg|gif|html?|php|tiff?|pdf|png))
  
  
  \1;
  </code></pre>
  
  <p>Translated to PHP, however does not work, having no effect; no errors.</p>
  
  <pre><code>preg_replace("/(\.(jpg|gif|html|php|tif|tiff|pdf|htm|png))/","\\1;",$string);
  </code></pre>