JS Regular string of all IMG image tags and full address and ALT description
<script>
var s= ' <img src= "/upload/image.jpg"/> This is some text <img src= "/upload/image.jpg" alt= "picture description"/> is also some text <img src= " Http://www.jzread.com/upload/image.jpg "/> Last Documents";
var regexp=/(<imgs*src= ") (?: Http://[w.] +)? ([^"]+) ("[^>]+>")/gim
S=s.replace (regexp, ' $1[url]http://www.jzread.com[/url]$2$3 ');
document.write (' <xmp> ' +s+ ' </xmp> ');
</script>
Method Two
<script>
var s= ' <img src= "/upload/image1.jpg"/> This is some text <img src= "/upload/image2.jpg" alt= "Picture description 2"/> is some text <img src= "Http://www.jzread.com/upload/image3.jpg"/> Last
var Imgreg =/<img.*?/?>/gi;
S=s.replace (Imgreg,function (IMGSRC) {
IMGSRC = Imgsrc.replace (/src=) (?: http://www.jzread.com)? *?)" /I, "src=" http://www.jzread.com$1 "")
if (Imgsrc.indexof ("alt=") ==-1) {
IMGSRC = Imgsrc.replace (//?>/i, "alt=" Picture description "/>");
}
return imgsrc;
});
alert (s);
</script>
Feature examples
The string is <img src= "/upload/image.jpg"/> This is some text <img src= "/upload/image.jpg" alt= "picture description"/> is also some text <img src= " Http://www.jzread.com/upload/image.jpg "/> Last file
is a mixed-text HTML code
Want to use the formal expression to automatically add the picture address full domain name, and then automatically add alt description text, but some are already with the ALT description, some are already have the full picture address
Can I replace it with a regular expression?