RegEx Help

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)
}
 
D

Daniel Pitts

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)

}


This is a Java newsgroup, not a JavaScript newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top