My variable htmlContent
contains a string with content in properly formatted HTML code, it contains multiple img
tags.
I'm trying to get all the values of the images src
attribute and put them in an array srcList
.
However, the problem I'm facing with the following code is that it always alerts an array with only 1 source value in it, while I have it set up to push all the source URLs to the array and not just one.
let srcList = [],
imgSrc,
regex = /<img.*src="(.*?)"/gi;
while ((imgSrc = regex.exec(htmlContent)) !== null) {
srcList.push(imgSrc[1]);
}
alert(JSON.stringify(srcList));
How can I make this work as I expect it to?