从HTML删除样式标记,CSS,脚本和HTML标记以纯文本 [英] Remove style tags, CSS, scripts and HTML tags from HTML to plain text

查看:182
本文介绍了从HTML删除样式标记,CSS,脚本和HTML标记以纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用常规的前pressions,如何从HTML删除样式标记,CSS,脚本和HTML标签为纯文本。

Using regular expressions, how do I remove style tags, CSS, scripts and HTML tags from HTML to plain text.

在ASP.NET C#。

In ASP.NET C#.

推荐答案

我不认为你正在寻找一个正则表达式来做到这一点,但是下面的正则表达式应该这样做,
如果你运行一个正则表达式替换:

I don't think you are looking for a regex to do this, however the following regex should do it, if you run a regex replace:

<[^>]*>

要在正则表达式使用替换为以下内容:

To use this in a Regex Replace to the following:

string myHtmlString = "<html><body>my test text</body></html>";

string myPlainTextString = Regex.Replace(myHtmlString ,"<[^>]*>",String.Empty);

我推荐你使用类似的HTML敏捷包虽然 - HTTP://htmlagilitypack.$c$cplex .COM /

,因为它有使这更容易被称为ConvertToPlainText的方法:

as it has a method to make this even easier called "ConvertToPlainText":

string myHtmlString = "<html><body>my test text</body></html>";

string myPlainTextString = ConvertToPlainText(myHtmlString);

这篇关于从HTML删除样式标记,CSS,脚本和HTML标记以纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆