.NET Regular Expressions - Shorter match
- by Xavier
Hi Guys,
I have a question regarding .NET regular expressions and how it defines matches.
I am writing:
var regex = new Regex("<tr><td>1</td><td>(.+)</td><td>(.+)</td>");
if (regex.IsMatch(str))
{
var groups = regex.Match(str).Groups;
var matches = new List<string>();
for (int i = 1; i < groups.Count; i++)
matches.Add(groups[i].Value);
return matches;
}
What I want is get the content of the two following tags. Instead it returns:
[0]: Cell 1</td><td>Cell 2</td>...
[1]: Last row of the table
Why is the first match taking </td> and the rest of the string instead of stopping at </td>?