将<label id="lab" onclick="save()" onblur="kk()"></label>替换为<label id="lab" ></label>
将标签的所有已on开头的函数替换为空
求正则表达式!!!!!

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = @"<label id=""lab"" onclick=""save()"" onblur=""kk()""> </label>";
                Regex reg = new Regex(@"on\w+=""[^""]+""");
                MatchCollection mc = reg.Matches(str);
                foreach (Match m in mc)
                {
                   str= str.Replace(m.Value, "");
                }
                Console.WriteLine(str);
            }
        }
    }<label id="lab"  > </label>
    Press any key to continue . . .
      

  2.   

    \s+on.+\="[^"]*"
    string result = Regex.Replace("text", @"\s+on.+\=""[^""]*""", RegexOptions.None);
      

  3.   

    on后面应该是字母。
    \s+on[a-zA-Z]+="[^"]*"
      

  4.   

    更正
     Console.WriteLine(Regex.Replace(str, @"\s+on.+\=""[^""]*""","", RegexOptions.None));
               
      

  5.   

    static void Main(string[] args)
            {
                string str = @"<label id=""lab"" onclick=""save()"" onblur=""kk()""> </label>";            
                Console.WriteLine(Regex.Replace(str, @"(?i)on\w+=""[^""]+""", "", RegexOptions.None));           
            }
      

  6.   

    - -
    string str = @"<label id=""lab"" onclick=""save()"" onblur=""kk()""> </label>";
    string result = Regex.Replace(str, @"\s+on[a-zA-Z]+=""[^""]*""", "",RegexOptions.None);
    Console.WriteLine(result);