const regex = /<img.*?src\s*=\s*"(.+?)"/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<img.*?src\\s*=\\s*"(.+?)"', 'gi')
const str = `<p>qweq</p>
<p>weq</p>
<p>we</p>
<p>qw</p>
<p>e</p>
<p>qw</p>
<p>e</p>
<p><img alt="Image title" class="fr-fin fr-dii" src="http://i.froala.com/download/f230c8e0f4dd83433e098c4bafeb3bc9bd12c54c.jpg?1445229186" width="300"></p><p>asdasdasdqweq qweqwe eqweqweqweqeqe e eqeqweqwe</p><p><img alt="Image title" class="fr-fin fr-dii" src = "http://i.froala.com/download/f230c8e0f4dd83433e098c4bafeb3bc9bd12c54c.jpg?1445229123" width= "300"></p>
<p><br>
</p>
<p><br>
</p>
<p>qw</p>
<p>e</p>
<p>q</p>
<p>e</p>
<p>q</p>
<p>e</p>
<p>qe</p>
<p>q</p>
<p>rqtqwt<a href="http://qweqweqe" rel="nofollow" target="_blank">qwtqtqtqwtqw</a></p>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions