我有一个字符串:
<span id="5" class="diamond" name="diamond">*</span> <span id="-1" class="diamond" name="diamond">*</span>
我也想找到任何id的所有跨度(*)。我如何使用正则表达式执行此操作? “模式”变量应该是什么?
string input = vsebina;
string pattern = "/<span id=\"-1\" class=\"diamond\" name=\"diamond\">*<\\/span>";
MatchCollection matches = Regex.Matches(input, pattern);
Console.WriteLine("Matches found: {0}", matches.Count);
string[] allDiamonds = new string[matches.Count];
int i = 0;
if (matches.Count > 0)
{
foreach (Match m in matches)
{
allDiamonds[i] = String.Format("{0}", m);
i++;
}
}
感谢您的帮助
答案 0 :(得分:2)