有一个文本,其中含有多个input标签,标签属性如下:<input id=0001  style="border:0;padding:0;margin:0;color:blue;text-decoration:underline;width:20px;cursor:pointer; value=XX  type=text />
想通过正则找出所有input,然后通过字符串截取得到id、value的值。可是在不同的浏览器中input属性的顺序有变化。因此截取出的值有误,不知道大家有没有别的方法,来得到每个input的ID和value属性值?正则表达式浏览器asp.netc#

解决方案 »

  1.   

    这个用什么正则
    用Jquery来获取ID和Value
      

  2.   

    jquery选择器多好用的
    $("input[type=text]")
      

  3.   

    (?is)<input[^/>]* id=(?<id>\S*)[^/>]* value=(?<v>\S*) [^/>]*/>
      

  4.   

    like this?
    http://www.cnblogs.com/insus/archive/2013/05/10/3072201.html
      

  5.   

    我用这个正则 匹配出来的 怎么还是 整个input标签啊?
      

  6.   

    取 分组内容哇。分组名id  就是ID
    分组名v   就是value
      

  7.   

    取 分组内容哇。分组名id  就是ID
    分组名v   就是value
    怎么取分组的值呢?
      

  8.   

    取 分组内容哇。分组名id  就是ID
    分组名v   就是value
    怎么取分组的值呢?
    //示例
    using System;
    using System.Text.RegularExpressions;class Example 
    {
       static void Main() 
       {
          string text = "One car red car blue car";
          string pat = @"(\w+)\s+(car)";      // Instantiate the regular expression object.
          Regex r = new Regex(pat, RegexOptions.IgnoreCase);      // Match the regular expression pattern against a text string.
          Match m = r.Match(text);
          int matchCount = 0;
          while (m.Success) 
          {
             Console.WriteLine("Match"+ (++matchCount));
             for (int i = 1; i <= 2; i++) 
             {
                Group g = m.Groups[i];
                Console.WriteLine("Group"+i+"='" + g + "'");
                CaptureCollection cc = g.Captures;
                for (int j = 0; j < cc.Count; j++) 
                {
                   Capture c = cc[j];
                   System.Console.WriteLine("Capture"+j+"='" + c + "', Position="+c.Index);
                }
             }
             m = m.NextMatch();
          }
       }
    }
    // This example displays the following output:
    //       Match1
    //       Group1='One'
    //       Capture0='One', Position=0
    //       Group2='car'
    //       Capture0='car', Position=4
    //       Match2
    //       Group1='red'
    //       Capture0='red', Position=8
    //       Group2='car'
    //       Capture0='car', Position=12
    //       Match3
    //       Group1='blue'
    //       Capture0='blue', Position=16
    //       Group2='car'
    //       Capture0='car', Position=21Match 有一个 Group 属性
    Regex.Match 方法