John John - 6 months ago 40 Question

vb2008 match text between html tags

hello i'm using

Visual Basic 2008 Express Edition

how is it possible to match text between tags?

for example i have a string :
<data>Text</data>more text...
, how i can get the
which is inside
( .Replace won't help).


My solution :

Public Function parseText(ByVal str As String, ByVal tag As String) As String
Dim match As Match = Regex.Match(str, "<" & tag & "\b[^>]*>(.*?)</" & tag & ">")
If match.Groups.Count = 2 Then
Return match.Groups(1).Value
Return "0"
End If
End Function

I use this because in my case the tags will be always without
id, class, width, href, src, style ....
just tag name (


You can use RegularExpressions.

    Dim s As String = "<data>Hello world</data>"
    Dim match As Match = Regex.Match(s, "<data\b[^>]*>(.*?)</data>")

    Dim text As String

    If match.Groups.Count = 2 Then
        text = match.Groups(1).Value
    End If