• 0
  • 0

JS正则替换过滤非法内容

2020-05-15 23 0 admin 所属分类:Javascript
//匹配各种标记
const rep = ($0, $1) = > {
    console.log('$0', $0)
    console.log('$1', $1)
    if (this.whiteTags.includes($1.toLowerCase())) {
        return $0;
    }
    return '';
};
//过滤过时标记 防止无法解析  如font
content = content.replace(/<([a-zA-Z0-9:_\-]+).*?>/gi, rep);
content = content.replace(/<\/([a-zA-Z0-9:_\-]+)>/gi, rep);


返回顶部