Using C# regular expressions to remove HTML tags

前端 未结 10 1827
悲&欢浪女
悲&欢浪女 2020-11-22 05:59

How do I use C# regular expression to replace/remove all HTML tags, including the angle brackets? Can someone please help me with the code?

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 06:41

    @JasonTrue is correct, that stripping HTML tags should not be done via regular expressions.

    It's quite simple to strip HTML tags using HtmlAgilityPack:

    public string StripTags(string input) {
        var doc = new HtmlDocument();
        doc.LoadHtml(input ?? "");
        return doc.DocumentNode.InnerText;
    }
    

提交回复
热议问题