user3781968
user3781968

Reputation: 11

How to get these images alt tag url with regex

I have a bunch of HTML code which contain these images:

<img alt=\"http://www.adsf1.net/static/1231.jpg\" width=\"100%\">
<img alt=\"http://www.1322.com/files/150818g58.jpg\" width=\"100%\">
<img alt=\"http://www.aerwef.org/sda/sdfawe.jpg\" width=\"100%\">

I manage to match these images with this regex

<img[^>]+\s*\/?>

But, I would like to get the url from the alt tag using JS, and store it into an array.

I would like to get a JS array like this (based on the above example)

["http://www.adsf1.net/static/1231.jpg", "http://www.1322.com/files/150818g58.jpg", "http://www.aerwef.org/sda/sdfawe.jpg"]

Upvotes: 1

Views: 437

Answers (2)

user3781968
user3781968

Reputation: 11

Thank you @pawan bhardwaj for the tips and clue. I have modified his code for a better match.

<img.*?alt=\\"(http[^"]*)\\".*?>

For others who are looking for something similar, hope this helps.

Upvotes: 0

Pawan B
Pawan B

Reputation: 4623

You can try this regex :

<img alt=\\"(http[^"]*)\\".*

Hope this helps.

link : https://regex101.com/r/mI3hV1/1

Upvotes: 2

Related Questions