java/android 正则表达式去除所有HTML标签

来源:互联网 发布:ubuntu安装flash命令 编辑:程序博客网 时间:2024/06/05 09:10

protected string str = "<table><tr><td>sdasasdsdd</td></tr></table><br><p>sds</p><img id='img1' src='http://www.baidu.com/img/baidu_logo.gif' width='100' height='50' alt=''>aaassss<br><img src='http://www.baidu.com/img/baidu_logo.gif' width='100' height='50' alt=''> 说是道 ";

protected void Page_Load(object sender, EventArgs e)

{

//string regexstr = @"<[^>]*>"; //去除所有的标签

//@"<script[^>]*?>.*?</script >" //去除所有脚本,中间部分也删除

// string regexstr = @"<img[^>]*>"; //去除图片的正则

// string regexstr = @"<(?!br).*?>"; //去除所有标签,只剩br

// string regexstr = @"<table[^>]*?>.*?</table>"; //去除table里面的所有内容

string regexstr = @"<(?!img|br|p|/p).*?>"; //去除所有标签,只剩img,br,p

str = Regex.Replace(str, regexstr, string.Empty, RegexOptions.IgnoreCase);

}

原创粉丝点击