62,046
社区成员
发帖
与我相关
我的任务
分享
<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>
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>
<option selected=""selected"" value=""/abella.aspx?avs=Brand%7cAbella&fa=2"">Page 2</option>
<option selected=""selected"" value=""/abella.aspx?avs=Brand%7cAbella&fa=3"">Page 3</option>
</select>";
Regex reg = new Regex(@"(?is)(?<=<select[^>]*?class=""paginateDD""[^>]*?>(?:(?!</?select).)*)<option[^>]*?value=(['""\s]?)([^'""]+)\1[^>]*?>(.*?)</option>");
foreach (Match m in reg.Matches(str))
Console.WriteLine(m.Groups[2].Value + " " + m.Groups[3].Value);
/*
/abella.aspx?avs=Brand%7cAbella&fa=1 Page 1
/abella.aspx?avs=Brand%7cAbella&fa=2 Page 2
/abella.aspx?avs=Brand%7cAbella&fa=3 Page 3
*/
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();
}