2013-03-08 74 views
0
<a href="http://www.try.com"><strong>Try link word</strong></a> 

你好。我怎麼能採取的我怎樣才能把一部分字符串與C#4.0正則表達式

http://www.try.com嘗試鏈接字

用C#4.0的正則表達式這個字符串的一部分?

我試過但沒有工作;

var expression = @"<a href=""(.*?)""><strong>(.*?)</strong>"; 
         Match m = Regex.Match(text, expression); 
         while (m.Success) 
         { 
          Response.Write("Match: " + m.Groups[0] + " <br> Area code: " + m.Groups[1] +"<br><hr><br>"); 
          m = m.NextMatch(); 
         } 
+1

沒有工作怎麼樣?你得到了什麼? – 2013-03-08 14:55:29

+0

回答

2

我想你的代碼,並得到這個:

Match: <a href="http://www.try.com"><strong>Try link word</strong> <br> Area code: http://www.try.com<br><hr><br>

(噓,下一次你有一些代碼,「不工作」,把你沒有得到你的問題,以及你的期望)。

更改:

Response.Write("Match: " + m.Groups[0] + " <br> Area code: " + m.Groups[1] +"<br><hr><br>");

Response.Write("Match: " + m.Groups[1] + " <br> Area code: " + m.Groups[2] +"<br><hr><br>");

了我:

Match: http://www.try.com <br> Area code: Try link word<br><hr><br>

這就是你想要的?

相關問題