Use regex to get image URL in HTML/Js

Based off the information you've given, this should work:

(https?:\/\/.*\.(?:png|jpg))

You can add more extensions by adding |ext after jpg. This will allow for strings with https as well.

Note: You may want to use the case insensitive modifier i to make the capture more inclusive. This would look like:

/(https?:\/\/.*\.(?:png|jpg))/i

A little late to the party, but in trying to do something similar to the OP, I created the following regex, which seems to handle relative links as well as absolute ones:

/([a-z\-_0-9\/\:\.]*\.(jpg|jpeg|png|gif))/i

Try this:

/"(http://[^"]*?\.(jpg|png))"/g

$1 is what you want.

Tags:

Html

Regex