2013-08-04 45 views
0

我堅持這個正則表達式問題在我的vb.net項目...正則表達式部分工作,並給我我不想要的數據!正則表達式來獲取在vb.net html特定的數據

HTML代碼示例如下所示:

<div id="card105148" class="cards">...</div> 

...

有很多的div但只有id和類的變化。該ID是allways「卡+(隨機數),並且該類可以是」卡「或」cardsp「。

我想要做的是抓取」卡(XXXXXXX)「後的ID而做到這一點的每個而言DIV

我的vb.net代碼如下所示:!``

Dim r As New System.Text.RegularExpressions.Regex("<div id=""card(.*?)""  class=""cards(.*?)"">") 
    Dim matches As MatchCollection = r.Matches(theusercp) 

    For Each itemcode As Match In matches 

     ListBox2.Items.Add(itemcode.Value.Split("""").GetValue(1)) 

    Next 

正如我所說的,當我運行的代碼,我得到的結果,但我讓他們帶例如: 例如:

1->> card105148 2->> card105132 3->> card153245 

我只需要沒有文字的號碼。

theusercp包含所有的html源代碼。

請幫忙來完成這個任務!另外,如果需要,我已準備好更改代碼!

回答

0

而不是

itemcode.Value.Split("""").GetValue(1) 

嘗試

itemcode.Groups(1).ToString() 
+0

謝謝很多!它工作!我現在只能得到這些數字。 – user2650060