工具类 util.img

    /**
     * @description transform emotion image url between code
     * @author x.radish
     * @param {String} html the html contents
     * @return {String}
     */

    transformImg:function (html) {
        var imgReg = /<imgs+data-type=['|"]emotion['|"]s+srcs*=s*['|"]([^s'"]+).*?/?>/g;
        var codeReg = /[:(d{1,3}):]/g;
        if (imgReg.test(html)) {
            html = html.replace(imgReg, function (match, capture) {
                var temp = capture.split("/");
                return "[:" + temp[temp.length - 1].split(".")[0] + ":]";
            });
        } else {
            html = html.replace(codeReg, function (match, capture) {
                return "<img data-type='emotion' src='emotion/" + capture + ".gif' />";
            });
        }
        return html;
    }
原文地址:https://www.cnblogs.com/x-radish/p/3158822.html