Get all images src from the HTML string with regex in Javascript

Today, we don't learn about regex (Regular expression), we'll learn about how to use it to get all images src from the HTML string like this one:




We create a function called getImages to get all of image urls from the HTML string above with a short piece of code below:




usage:

const imgs = getImages(htmlString);
console.log(imgs); // ["image-url-1.png", "image-url-1.png"]


© 2019 4codev

Created with love by Sil.