V
vunet.us
Please, assist with RegEx which reads String object and gets SRC of
all HTML IMG tags. This code does it but it returns "<img src='"
prefix in front of it if using (/<img[^>]+src=('|")([^'"]+)/ig).
Thanks.
JavaScript:
var strText = "ab cd efg hig klmnop <img src='file.jpg'> ot her"+
" e <IMG SRC='www.g.com/file2.jpg' BORDER=0>";
var separateBy = "\n";
var result = ""; // if no match, use this
var allMatches = strText.match(/<img[^>]+src=('|")([^'"]+)/ig);
if (allMatches) {
result = "";
for (var i = 0; i < allMatches.length; i++) {
if (i != 0) result += separateBy;
result += allMatches;
}
}
alert(result)
}
all HTML IMG tags. This code does it but it returns "<img src='"
prefix in front of it if using (/<img[^>]+src=('|")([^'"]+)/ig).
Thanks.
JavaScript:
var strText = "ab cd efg hig klmnop <img src='file.jpg'> ot her"+
" e <IMG SRC='www.g.com/file2.jpg' BORDER=0>";
var separateBy = "\n";
var result = ""; // if no match, use this
var allMatches = strText.match(/<img[^>]+src=('|")([^'"]+)/ig);
if (allMatches) {
result = "";
for (var i = 0; i < allMatches.length; i++) {
if (i != 0) result += separateBy;
result += allMatches;
}
}
alert(result)
}