2012-07-26 62 views
-2

我有如下的字符串:C#正則表達式:如何從字符串中提取內容?

...[down]<a title="Download: Click Here" href="http://www.domain.com/T60B8JK2WT/" target="_blank"><strong> blah blah (2011)(1 - 22)</strong></a> <a title="Download: Click Here" href="http://www.domain.com/5FBLQYBQTV/" target="_blank"><strong> blah blah (2011) </strong></a>[/down]... 

我怎樣才能找到字符串[down][/down]標籤&得到所有href屬性& text of each link在[下] [/向下]標籤,並把它放在一個data table,每行表格中包含標題& url字段?

感謝

+2

如果你嘗試至少刮盜版網站消毒例子... – Alex 2012-07-26 08:35:17

回答

0

您的代碼應該是這樣的:

foreach (Match match in Regex.Matches(inputString, 
             @"\[down\](?<content>.+)\[/down\]")) 
{ 
    var content = match.Groups["content"].Value; 

    var hrefs = new List<string>(); 

    foreach (Match matchhref in Regex.Matches(t, @"href=""(?<href>[^""]+)""")) 
    { 
     hrefs.Add(matchhref.Groups["href"].Value); 
    } 
} 
相關問題