1
我有一个关于.NET正则表达式的问题以及它如何定义匹配。 我写:.NET正则表达式 - 更短的匹配
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;
}
我想要的是得到以下两个标签的内容。相反,它返回:
[0]: Cell 1</td><td>Cell 2</td>... [1]: Last row of the table
为什么第一场比赛以</TD >和字符串的其余部分,而不是在</TD >停止?
顺便说一句,强制性警告:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#1732454 – cHao 2010-05-28 03:35:27