---
title: "正则表达式过滤html"
author: "siruoxian"
date: "2010-11-10T14:24:58Z"
tags: []
categories: ["Web前端"]
slug: "html"
draft: false
lastmod: "2011-04-20T16:26:47Z"
id: 807603
url: "https://siruoxian.iteye.com/blog/807603"
---

function ClearHTML(str){  
    str = str.replace(/&lt;\\/?\[^&gt;]+&gt;/g,''); //去除HTML tag  
    str = str.replace(/\[ | ]\*\\n/g,'\\n'); //去除行尾空白  
    str = str.replace(/\\n\[\\s| | ]\*\\r/g,'\\n'); //去除多余空行  
    str=str.replace(/&nbsp;/g, "") ; //去除空格  
    return str;  
    }