似乎 JS 只是替换了正则表达式字符串的最后一个匹配项。我的正则表达式很可能有问题。
var data = "<div class=\"separator\" style=\"clear: both; text-align: center;\"><img border=\"0\" src=\"https://lh3.googleusercontent.com/-dJnr7dsB21Y/UEhijTGNweI/AAAAAAAAA_w/DWiWYDOHXBA/s640/blogger-image-438529929.jpg\" /></div><div class=\"separator\" style=\"clear: both; text-align: center;\"><img border=\"0\" src=\"https://lh4.googleusercontent.com/-B3wU95K7DLI/UEhiuu75V-I/AAAAAAAAA_4/lxzGd2WajNE/s640/blogger-image-1479348845.jpg\" /></div>";
var regex = /<img (.*)src=\"(.*)\" (.*)\/>/g;
console.log("Before: "+data);
console.log("After: "+data.replace(regex, "[$2]"));
它输出以下内容;
Before: <normal before string>
After: <div class="separator" style="clear: both; text-align: center;">[https://lh4.googleusercontent.com/-B3wU95K7DLI/UEhiuu75V-I/AAAAAAAAA_4/lxzGd2WajNE/s640/blogger-image-1479348845.jpg]</div>
(只返回最后一张图片)
顺便说一下,这是 node.js。