62,041
社区成员
发帖
与我相关
我的任务
分享
Regex re = new Regex(@"(?is)<ZD:PROLIST\s*(?<parameter>[^>]+?=[^>]+?)>(?<tag>.+?)</ZD:PROLIST.*?>");
MatchCollection mac = re.Matches(str);
foreach (Match var in mac)
{
sb.Append(var.Value + "\n" + var.Groups["tag"].Value + "\n" + var.Groups["parameter"].Captures[0]);
}
string s = @"<zd:prolist size=""5"" type=""1"">
<li><span>多个标签测试</span>
</li>
</zd:prolist>";
Regex reg = new Regex(@"(?is)<ZD:PROLIST(?<parameter>\s+[^>]+?=[^>]+?)*>(?<tag>.+?)</ZD:PROLIST.*?>");
foreach (Match m in reg.Matches(s))
{
Console.WriteLine("Value:\n" + m.Value);
Console.WriteLine("Tag:\n" + m.Groups["tag"].Value);
Console.WriteLine("Parameters:");
foreach (Capture c in m.Groups["parameter"].Captures)
{
Console.WriteLine(c.Value);
}
}
string str = @"<zd:prolist>
<li><span>多个标签测试111</span>
</li>
</zd:prolist>
<zd:prolist size=""5"" type=""1"">
<li><span>多个标签测试222</span>
</li>
</zd:prolist>";
Regex reg = new Regex(@"(?is)<zd:prolist\s*(?:([^=]+)=""([^""]+)""\s*)*?>(.*?)</zd:prolist>");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Groups[3].Value);
for (int i = 0; i < m.Groups[1].Captures.Count; i++)
{
Console.WriteLine("Key:{0} Value:{1}", m.Groups[1].Captures[i].Value,m.Groups[2].Captures[i].Value);
}
}