Search code examples
regexvb.nethttpwebrequest

regex to get html specific data in vb.net


I'm stuck with this regex problem in my vb.net project ... the regex works partially and gives me data that I don't want!

The html code sample look like this :

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

...

There is many divs but only the id and the class changes. The id is allways "card+(random numbers) and the class can be "cards" or "cardsp" .

What I want to do is grab the numbers after the "card(XXXXXXX)" in the id of the div and do that for each div that is concerned!

My vb.net code look like this :``

 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

As I said, when I run the code, I get results but I get them with the id name before them. example:

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

I just need the number without the text.

theusercp contain all the html source code.

Please, help to to achieve this task! Also, I'm ready to change the code if it needed!


Solution

  • Instead of

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

    try

    itemcode.Groups(1).ToString()