C# 使用正则表达式和正则表达式查找字符串

C# 使用正则表达式和正则表达式查找字符串,c#,regex,C#,Regex,我有这个文本,我试着打印a1和a2 <a href="a1" title="t1"> k1 </a> <a href="a2" title="t2"> k2 </a> 以下是我的尝试: string html = "<a href=\"a1\" title=\"t1\"> k1 </a>"; html += "<a href=\"a2\" title=\"t2\"> k2 </a>

我有这个文本,我试着打印
a1
a2

<a href="a1" title="t1"> k1 </a>
<a href="a2" title="t2"> k2 </a>

以下是我的尝试:

string html =  "<a href=\"a1\" title=\"t1\"> k1 </a>";
       html += "<a href=\"a2\" title=\"t2\"> k2 </a>";

 //here is how I think my logic expression should work:
 //<a href=" [something that is not quote, 0 or more times] " [anything] </a>
Regex regex = new Regex("<a href=\"([^\"]*)\".*</a>");
foreach (Match match in regex.Matches(html)
    Console.WriteLine(match.Groups[1]);
string html=”“;
html+=“”;
//以下是我认为我的逻辑表达式应该如何工作:

// 正则表达式
*
正在消耗第二个
之前的所有字符。您需要的是使用
*?
进行惰性消耗,以便它只消耗第一个
之前的所有字符:


Regex Regex=new Regex(“

我不使用c语言编写代码,但我认为
*
应该是
*?
所以它是不贪婪的。现在你将转到最后一个
@chris85哦,该死的,你说得对,谢谢你哇哦,我解决了一个c,有点..这样,
(“
Regex regex = new Regex("<a href=\"([^\"]*)\".*?</a>");