const html = '<img src="image1.jpg" data-a="aa"><img src="image22.jpg" data-a="a2a"><p>Some text with no image</p><img src="i23mage3.jpg" 1 >';
const regex = /(<img.*?src=")(.*?)(".*?>)/g; //用于匹配<img>标签中的src属性的正则表达式
const matches = html.match(regex); //使用match()方法获取匹配结果
var sources = matches.map(match => match.replace(regex, '$2')); //$序号从1开始,$1为第一个分组
var sources = matches.map(match => match.replace(regex, '$1$2'+'好$3')); //
console.log(sources)
正文完