C # HTML Tag Filtering

Source: Internet
Author: User

Original article: http://www.ityoudao.com/Web/Csharp_590_1509.html

You can customize it as needed...

Private string filterhtml (string html) {system. text. regularexpressions. regEx regex1 = new system. text. regularexpressions. regEx (@ "<SCRIPT [ss] + </script *>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex2 = new system. text. regularexpressions. regEx (@ "href * = * [ss] * script *:", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex3 = new system. text. regularexpressions. regEx (@ "No [ss] * =", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex4 = new system. text. regularexpressions. regEx (@ "<IFRAME [ss] + </iframe *>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex5 = new system. text. regularexpressions. regEx (@ "<frameset [ss] + </frameset *>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex6 = new system. text. regularexpressions. regEx (@ "] +>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex7 = new system. text. regularexpressions. regEx (@ "</P>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex8 = new system. text. regularexpressions. regEx (@ "<p>", system. text. regularexpressions. regexoptions. ignorecase); system. text. regularexpressions. regEx regex9 = new system. text. regularexpressions. regEx (@ "<[^>] *>", system. text. regularexpressions. regexoptions. ignorecase); html = regex1.replace (HTML, ""); // filter <SCRIPT> </SCRIPT> tags html = regex2.replace (HTML ,""); // filter href = javascript: (<A>) attribute html = regex3.replace (HTML, "_ disibledevent ="); // filter other controls on... event html = regex4.replace (HTML, ""); // filter iframe html = regex5.replace (HTML, ""); // filter frameset html = regex6.replace (HTML ,""); // filter frameset html = regex7.replace (HTML, ""); // filter frameset html = regex8.replace (HTML, ""); // filter frameset html = regex9.replace (HTML, ""); // html = html. replace ("", ""); html = html. replace ("</strong>", ""); html = html. replace ("<strong>", ""); html = RegEx. replace (HTML, "[\ f \ n \ r \ t \ v]", ""); // filter the line feed tab return HTML ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.