2013-03-08 76 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>

这就是你想要的?

相关问题