const regex = /<img[\w\W]+?srcSet="[^"]+(?<img>https?:\/\/[^" ]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<img[\\w\\W]+?srcSet="[^"]+(?<img>https?:\\\/\\\/[^" ]+)', 'gm')
const str = `<img data-test="v-img" src="https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=752x" alt="" width="3200" height="2400" sizes="(max-width: 767px) 100vw, (max-width: 919px) calc(100vw - 32px), (max-width: 1278px) calc(100vw - 240px), 1024px" draggable="false" srcSet="https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=300x225 300w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=400x300 400w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=600x450 600w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=752x564 752w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1024x768 1024w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1200x900 1200w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1504x1128 1504w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=2048x1536 2048w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=2400x1800 2400w" class="v-img content-block border-radius-8" data-v-5e868365>`;
// 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