title: Regex for Replacing Absolute URLs with Relative URLs
body: <p>How can I write a regex expression that will convert any absolute URLs to relative paths. For example:</p>
  
  <pre><code>src="http://www.test.localhost/sites/ 
  </code></pre>
  
  <p>would become </p>
  
  <pre><code>src="/sites/"
  </code></pre>
  
  <p>The domains are not static.</p>
  
  <p>I can't use parse_url (as per this <a href="https://stackoverflow.com/questions/7017080/convert-absolute-to-relative-url-with-preg-replace">answer</a>) because it is part of a larger string, that contains no-url data as well.</p>