0

Like the title says I have the html source that contains the code below. I am trying to grab the number 25 which can change so I think I would use the wildcard .* but I am not sure how to grab it because I the number is on its own line. I usually used one line of html then used the split method and split the double quotes then getting the value. I know how to do html webrequest and webresponse, so I have no problem getting the source. Any help with the regex expression would be appreciated.

<td class="number">25</td>

Edit: This is what I used to get the source.

Dim strURL As String = "mysite"
Dim strOutput As String = ""
Dim wrResponse As WebResponse
Dim wrRequest As WebRequest = HttpWebRequest.Create(strURL)
wrResponse = wrRequest.GetResponse()

Using sr As New StreamReader(wrResponse.GetResponseStream())
    strOutput = sr.ReadToEnd()
    'Close and clean up the StreamReader
    sr.Close()
End Using
David -
  • 2,009
  • 1
  • 13
  • 9

1 Answers1

1

Instead of a Regex, it is possible to use a string search to pull out the text, e.g.:

Sub Main()
    Dim html = "<td class=""number"">" + vbCrLf + "25" + vbCrLf + "</td>"
    Dim startText = "<td class=""number"">"
    Dim startIndex = html.IndexOf(startText) + startText.Length
    Dim endText = "</td>"
    Dim endIndex = html.IndexOf(endText, startIndex)        
    Dim text = html.Substring(startIndex, endIndex - startIndex)
    text = text.Trim({CChar(vbLf), CChar(vbCr), " "c})
    Console.WriteLine(text)
End Sub
Phillip Trelford
  • 6,513
  • 25
  • 40