JS正则过滤

function FiltrationHTML(HTML)
{
var temp = HTML;
var url=http://www.rr555.com/news/newsview.php?nid=1877
temp = temp.replace(/<script[^>]*?>(.|\n)*?<\/script>/gim,""); //过滤<script></script>块
temp = temp.replace(/<(p |p>)/gi, "『〈$1"); //分段 <p>
temp = temp.replace(/<(\/p)/gi, "『〈$1"); //分段 </p>
temp = temp.replace(/<(sup>)/gi, "『〈$1"); //上标 <sup>
temp = temp.replace(/<(\/sup)/gi, "『〈$1"); //上标末 </sup>
temp = temp.replace(/<(sub)/gi, "『〈$1"); //下标 <sub>
temp = temp.replace(/<(\/sub)/gi, "『〈$1"); //下标末 </sub>
temp = temp.replace(/<(table)/gi, "『〈$1"); //表格 <table>
temp = temp.replace(/<(\/table)/gi, "『〈$1"); //表格末 </table>
temp = temp.replace(/<(tr |tr>)/gi, "『〈$1"); //行 <tr>
temp = temp.replace(/<(\/tr)/gi, "『〈$1"); //行末 </tr>
temp = temp.replace(/<(td |td>)/gi, "『〈$1");//列 <td>
temp = temp.replace(/<(\/td)/gi, "『〈$1"); //列末 </td>
temp = temp.replace(/<(img )/gi, "『〈$1"); //图片 <img>
temp = temp.replace(/<(br)/gi, "『〈$1"); //换行符 <br>
temp = temp.replace(/(『〈[^>]*)>/gi,"$1〉』"); //右括号

temp = temp.replace(/<[^>]*>/gi,""); //过滤其它所有"<...>"标签
temp = temp.replace(/\&nbsp;/gi," "); //替换所有&nbsp;为空格

temp = temp.replace(/『〈/gi,"<"); //恢复<
temp = temp.replace(/〉』/gi,">"); //恢复>

temp = temp.replace(/(<table)[^>]*(>)/gi,"$1 border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"border-collapse: collapse\" bordercolor=\"#333333\" width=\"100\%\"$2"); //清除表格属性并加样式
temp = temp.replace(/(<[^>]*)colspan(=[^\s>]*)/gi,"$1 『col$2』"); //给<td>中需要的属性加『』
temp = temp.replace(/(<[^>]*)rowspan(=[^\s>]*)/gi,"$1 『row$2』"); //给<td>中需要的属性加『』

temp = temp.replace(/(<tr)[^>]*(>)/gi,"$1$2"); //清除TR属性
temp = temp.replace(/(<td)[^>『]*(>)/gi,"$1$2"); //清除不包含『』的TD的属性
temp = temp.replace(/(<td)[^>『]*『/gi,"$1『"); //替换 <td...『之间内容
temp = temp.replace(/(<[^>』]*』)[^>]*(『[^>『]*>)/gi,"$1$2"); //替换『』...『』之间内容
temp = temp.replace(/(』)[^>』]*(>)/gi,"$1$2"); //替换『』...>之间内容
temp = temp.replace(/<p[^>]*>/gi,"<p>"); //清除<p>中多余属性

temp = temp.replace(/『(col)(=\d{1,4})』/gi," $1"+"span"+"$2"); //还原 colspan
temp = temp.replace(/『(row)(=\d{1,4})』/gi," $1"+"span"+"$2"); //还原 rowspan
temp = temp.replace(/(<img)[^>]*(>)/gi,"$1 src=\"\""+"$2"); //替换 <img>

return temp;
}

你可能感兴趣的:(字符串,特殊字符,在线编辑器)