js替换字符串中img标签src路径

1,328 阅读1分钟
var replacestr = pagestr.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi,function(match,capture){
    //返回整个标签
    match = match.replace('/static/web',path.join(__static,'/web'));
    return match;
    //capture,返回每个匹配的字符串
    // capture = capture.replace('/static/web',path.join(__static,'/web'));
    return capture;
});
  • 说明:这里path.join()是调用了nodejs中的path