My goal is to change the src of multiple image HTML elements in plain text (before they show up in the browser).
Here's my current progress:
var base = './images';
var sample = '<p><img src="1.png" alt="image-1"></p><p><img src="2.png" alt="image-2"></p><p><img src="3.png" alt="image-3"></p>';
sample = sample.replace(/(<img.+src=")(?!http:\/\/)(.*?)"/g, '$1' + base + '/$2"');
$('pre').text(sample);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre></pre>
However, it seems to only replace the src of the last image element. What am I overlooking?