Reputation: 244
I have a string full of html & which reads
Dim strHml as string = "<html><head><title></title></head><body><div class="normal">Dog</div>
<div class="normal">Cat</div><div class="normal">Elephant</div><div class="normal">Giraffe</div><div class="normal"><div><p>Random Div</p></div>Lion</div><div>Wolf</div>
<div>Tiger</div></body></html>"
I want to somehow be able to pull all the div tags and their content and put each one into an array have looked at split function and regular expressions but no clear and easy solution has presented itself as yet.
I have amended this slightly to incorporate nested div tags, but those tags I still need returning in the format :-
<div class="normal"><div><p>Random Div</p></div>Lion</div>
Upvotes: 0
Views: 2901
Reputation: 166346
I tested this in vb.net using regex.
Is that what you needed?
Dim reg = New Regex("<div>(.*?)</div>")
Dim matches = reg.Matches(strHml)
For Each mat As Match In matches
Dim s As String
s = mat.Value
Next mat
Upvotes: 4