日期:2014-05-18  浏览次数:20568 次

求正则表达式(huangwenquan123)
获取到的html代码有多个select标签 我想获取
C# code
<select name="ProductsSearchLayout$BottomSectionPager$PagerLinksDropDownList" id="ProductsSearchLayout_BottomSectionPager_PagerLinksDropDownList" class="paginateDD" onChange="MM_jumpMenu('parent',this,0)">
        <option selected="selected" value="/abella.aspx?avs=Brand%7cAbella&amp;fa=1">Page 1</option>
 
    </select>


这个里面的option value 和Page 1怎么获取呢

------解决方案--------------------

C# code

static void Main(string[] args)
            {

                string str = @"<select name=""ProductsSearchLayout$BottomSectionPager$PagerLinksDropDownList"" id=""ProductsSearchLayout_BottomSectionPager_PagerLinksDropDownList"" class=""paginateDD"" onChange=""MM_jumpMenu('parent',this,0)"">
        <option selected=""selected"" value=""/abella.aspx?avs=Brand%7cAbella&amp;fa=1"">Page 1</option>
 
    </select>";
              
                Regex re = new Regex(@"(?is)<select[^>]+id=""ProductsSearchLayout_BottomSectionPager_PagerLinksDropDownList""[^>]+>\s*<option[^>]+value=""([^""]+)"">([^<]+)</option>", RegexOptions.None);

                Match ma = re.Match(str);
                Console.WriteLine(ma.Groups[1].Value);  // 输出值为:/abella.aspx?avs=Brand%7cAbella&amp;fa=1
                Console.WriteLine(ma.Groups[2].Value);  // 输出值为:Page 1
                Console.ReadLine();
            }

------解决方案--------------------
回家在写下。还在公司处理事情。