用正则表达式获取图片img标签的url

var reg=/<img\s+.*?src=(?:'(.+?)'|"(.+?)")\s*.*?(?:>|\/>)/igm
var strXml ="sdfdfsadf <img src='xx/aa.jpg'/>sdfsdfsdf<img src='gg.jpg'/>sdfsdfsd<img size='19' src='cgg.jpg' n='20'>";
var result = []; 
var match; 
while( match=reg.exec(strXml) ){ 
result.push(match[0],match[1]); 
} 
alert(result);

相关推荐