Use regex to get image URL in HTML/Js
regex find all images in html
regex get image tag
image url validator
I want to get some URLs of images in Js/HTML:
var a = "http://sub.domain.com/uploads/files/11-11-2011/345301-574-1182-393/2202.jpg"; var b = "http://sub.domain.com/uploads/files/23-11-2011/234552-574-2321-232/asd.png";
Looking for solution that will detect image url. So the output will be:
Based off the information you've given, this should work:
You can add more extensions by adding
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:
Regex image URL, Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, Match between 0 and 1 of the preceding token. I am validating URL with following regular expression. I want to validate google.com also but it returns false. What can be changed in R.E below to validate google.com. console.log(learnRegExp('ht
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:
$1 is what you want.
var regex = /(http[s]?://.*.(?:png|jpg|gif|svg|jpeg))/i;
This is the result you want
Regex to get all image links, As it stands, all of the provided Regular Expressions will fail on local images, as well as loop through the matches ---> <cfloop condition="matcher.find()"> < cfset src <img - Literal string "<img", match the opening tag \s+ - Match one or more� The src property sets or returns the value of the src attribute of an image. The required src attribute specifies the URL of an image. Note: The src property can be changed at any time. However, the new image inherits the height and width attributes of the original image, if not new height and width properties are specified.
- This will fail in situations like src="mail.google.com/mail/u/0/images/cleardot.gif" style="background:url(ssl.gstatic.com/mail/sprites/…) . What works for me is (https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))
- I think this is better:
- yeah +1 : for example : someurl.svg.png (wiki eg.)
- Altough @Amarsh is right, OP asked for URL, not a generic path, but URL (which I believe is required to have scheme (e.g. http: ))
- If you already have
<img ...>tag parsed out and want to get the src no matter what it contains, this worked for me
\Wmeans non-word characters and
\1is referencing the first defined group. Don't use
*to get only non-empty - might not work if
<img ...>has more attributes!