Remove HTML tags and replace script tags

Source: Internet
Author: User

   1:  //<summary>
   2:  ///        Remove HTML tags
   3:  //        </summary>
   4:  ///        <param name= "nohtml" > including HTML source code </param>
   5:  ///        <returns> removed text after </returns>
   6:  public        staticstring removehtml (string htmlstring)
   7:          {
   8:              if (string. IsNullOrEmpty (htmlstring))
   9:              {
  Ten:                  returnstring. Empty;
One   :              }
  :              //Delete script
@ "<script[^>]*?>.*?</script>" ",                Regexoptions.ignorecase);
  :  
  :              //delete HTML
  :              @ < (. [ ^>]*) >"", regexoptions.ignorecase);
  :              @ "([\ r \ n]) [\s]+""", regexoptions.ignorecase);
  :              @ "--" "", regexoptions.ignorecase);
  :              @ "<!--. *" "" ", regexoptions.ignorecase);
  :              @ & (quot| #34); "\" ", Regexoptions.ignorecase);
  :              @ "& (amp| #38);" "&", regexoptions.ignorecase);
  :              @ "& (lt| #60);" "<", regexoptions.ignorecase);
At   :              @ "& (gt| #62);" ">", Regexoptions.ignorecase);
@ "& (nbsp| #160);"               "", Regexoptions.ignorecase);
@ "& (iexcl| #161);"               "\xa1", regexoptions.ignorecase);
  :              @ "& (cent| #162);" "\xa2", regexoptions.ignorecase);
@ "& (pound| #163);"               "\xa3", regexoptions.ignorecase);
  :              @ "& (copy| #169);" "\xa9", regexoptions.ignorecase);
  £ º              @ "(\d+);" "", Regexoptions.ignorecase);
  :              htmlstring.replace ("<" ");
To   :              htmlstring.replace (">" ");
  :              htmlstring.replace ("\ r \ n"");
  :  
  :              return htmlstring;
  :          }
  £ º  
  Panax Notoginseng  :
Block   :          #region Regular expression replaces script code that contains scripts for scripting attacks
  //  /        <summary>
Max   :  ///        Regular expression replace script code with script attack
In   :  ///        author:Andrew.He
  //  /        </summary>
  //  /        <param name= "scriptstring" > String containing script attack </param>
A   :  ///        <returns> Replace script attack string </returns>
  :  public        staticstring removescript (string scriptstring)
  :          {
A   :              if (string. IsNullOrEmpty (scriptstring))
  :              {
  £ º                  return scriptstring;
  :              }
  Wuyi:  
  :              //Perform a replacement operation
  :              @ "<[]*script""[Script", regexoptions.ignorecase);
Si   :              @ "/[]*script[]*>" "/script]", regexoptions.ignorecase);
  :  
  £ º              return scriptstring;
  £ º          }
  :          #endregion

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.