求正则表达式(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&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&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&fa=1 Console.WriteLine(ma.Groups[2].Value); // 输出值为:Page 1 Console.ReadLine(); }
[解决办法]
回家在写下。还在公司处理事情。