1. Regularly get the img tag in the string
try {
var str = '<P>xczxzxzxcxcxc<IMG src="http://file.ynet.com/2/1612/12/12119048.jpg" mce_src="http://file.ynet.com/2/1612/12/12119048.jpg">dfsd<IMG src="http://file.ynet.com/2/1612/12/12119048.jpg" mce_src="http://file.ynet.com/2/1612/12/12119048.jpg">sdfs</P>';
//获取img 标签
var s = str.match(/<img\s*src=\"([^\"]*?)\"[^>]*>/gi);
for (var i = 0; i < s.length; i++) {
console.info(s[i]);
}
}
catch (e) {
alert(e);
}
Cut processing according to img tag
s2=str.split(/\<img\s*src=\"([^\"]*?)\"[^>]*>/gi);
Second, js uses regular to obtain or replace the src attribute
content.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
console.log(capture);
});
output:
http://www.jb51.net/images/logo.gif
More:
WeChat applet tab usage and organization
Open other applets and jump between applets in WeChat applet