Reputation: 463
I have a string:
<span id="5" class="diamond" name="diamond">*</span> <span id="-1" class="diamond" name="diamond">*</span>
I want too find all the spans ( * ) with any id. How do I do this with regex? what should the "pattern" variable be?
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++;
}
}
Thank you for your help
Upvotes: 0
Views: 57
Reputation: 67988
(<span\s*id="-?\d+"(?:(?!<\/span>).)*<\/span>)
Try this.See demo.
http://regex101.com/r/hQ1rP0/66
Upvotes: 2