C # removing javascript events using the regular expression in the regular form

Source: Internet
Author: User
Private static string FixTag (Match tagMatch)

{

List <string> events = new List <string> ();

 

Events. Add ("onclick ");

Events. Add ("onmousedown ");

Events. Add ("onmouseover ");

Events. Add ("onmouseout ");

Events. Add ("onmouseup ");

 

Bool flag = true;

Regex regex = new Regex ("([-\ w] +) (= (\ "[^ \"] * \ "| '[^'] * '| (# | _)? \ W + ))? ");

String input = tagMatch. Value;

String str2 = "";

If (input. IndexOf ("</") = 0)

{

Return input. ToLower ();

}

String str3 = tagMatch. Groups [1]. Value. ToLower ();

Str2 = "<" + str3;

Foreach (Match match in regex. Matches (input ))

{

String text1 = match. Value;

String item = match. Groups [1]. Value;

String str5 = match. Groups [3]. Value. TrimStart (new char [] {'"'}). TrimEnd (new char [] {'"'});

If (! Flag |! Events. Contains (item ))

{

String str6 = str2;

Str2 = str6 + "" + item. ToLower () + "= \" "+ str5 + "\"";

}

}

Return (str2 + "> ");

}

Public static string RemoveJavaScriptEventsFromTags (string input)

{

 

Input = new Regex (@ "</? ([-\ W] +) ([^>] +)?> "). Replace (input, new MatchEvaluator (FixTag ));

Return input;

}

 

 

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.