2014-01-15 156 views
0

在vb.net正則表達式2010正則表達式(正則表達式)在vb.net

我想提取的字體標籤之間的數量從一個網站在我的vb.net形式

<html> 
.... 
When asked enter the code: <font color=blue>24006 </font> 
.... 
</html> 

數量是自動生成

我使用:

Dim str As String = New WebClient().DownloadString(("http://www.example.com")) 
    Dim pattern = "When asked enter the code: <font color=blue>\d{5,}\s</font>" 
     Dim r = New Regex(pattern, RegexOptions.IgnoreCase) 
     Dim m As Match = r.Match(str) 
     If m.Success Then 
      Label1.Text = "Code" + m.Groups(1).ToString() 
      m = m.NextMatch() 

     Else 
      Debug.Print("Failed") 
     End If 

,但得到的輸出:

代碼

===========================

感謝

對不起,我的英文不好..

回答

0

這樣的事情應該可以幫到你。異常處理由您決定。

Dim matchCollection As MatchCollection = regex.Matches("When asked enter the code: <font color=blue>24006 </font>","<font color=.*?>(.*?)</font>",ReaderOptions.None) 
For Each match As Match In matchCollection 
    If match.Groups.Count >0 then 
    Console.WriteLine(match.Groups(1).Value) 
end if 
Next   

或帶着幾分LINQ

Dim matchCollection As MatchCollection = regex.Matches("When asked enter the code: <font color=blue>24006 </font>","<font color=.*?>(.*?)</font>",ReaderOptions.None) 
For Each match As Match In From match1 As Match In matchCollection Where match1.Groups.Count >0 
    Console.WriteLine(match.Groups(1).Value) 
Next   

更多信息,請參閱VB.NET Regex.MatchVB.NET Regex.Matches