title: regex replace only the first occurrence of every match
body: <p>How can I replace only the first occurrence of every match?</p>
  
  <p>Example.</p>
  
  <p>The following string</p>
  
  <pre><code>var toReplace='href="/3" href="/3/a" href="a/3" href="h/3/a/3/b"'
  </code></pre>
  
  <p>after replace should be like:</p>
  
  <pre><code>'href="*" href="*/a" href="*" href="*/a/3/b"'
  </code></pre>
  
  <p>I use this regex</p>
  
  <pre><code>toReplace.replace(/(href=")[^"]*(\/3)/,'$1*')
  </code></pre>
  
  <p>but the result is this:</p>
  
  <pre><code>'href="*" href="*/a"  href="*" href="*/b" '
  </code></pre>
  
  <p>The last href in that case becomes <code>href="*/b" instead of href="*/a/3/b"</code></p>
  
  <p>Any ideas?</p>