title: How can I preg_match script tag src, but avoid effecting img tag src?
body: <p>I have to match local src's and make them load via the web. Example:</p>
  
  <pre><code>src="/js/my.js"&gt;
  </code></pre>
  
  <p>Becomes:</p>
  
  <pre><code>src="http://cdn.example.com/js/my.js"&gt;
  </code></pre>
  
  <p>This is what I have now:</p>
  
  <pre><code>if (!preg_match("#&lt;script(.+?) src=\"http#i",$page)){ 
  $page = preg_replace("#&lt;script(.+?) src=\"#is", "&lt;script$1 src=\"$workingUrl", $page); 
  }
  </code></pre>
  
  <p>It works fine when it encounters something like this:</p>
  
  <pre><code>&lt;script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.8.3'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>It fails when it encounters something like this:</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;
  window.moveTo(0,0);
  window.resizeTo(screen.width,screen.height);
  &lt;/script&gt;
  </code></pre>
  
  <p>If the script tag doesn't contain a src it will then find the src of the first image tag and switch out its URL.</p>
  
  <p>I need to know how to get it to terminate the match on the script tag only and/or how to perform the replacement better.</p>