Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex, everything between 2 html tags vb.net

Tags:

vb.net

i'm trying to get some information of a webpage via regex on visual basic 2010

it's something like this:

<SPAN CLASS="clear"></SPAN>
<h2> blabla </h2>
<h2> blabla </h2>
<b> blabla </b>

etc etc

<SPAN CLASS="clear"></SPAN>

what i want is everything between the 2 also the h2 tags and every other html tag that exists.

is this possible?

i've already tried (.?) and . and \w* but it doesn't return anything...

like image 711
user1216583 Avatar asked Aug 01 '26 06:08

user1216583


1 Answers

It's probably best to use an XML parser for that, but I'm assuming it's a one-off scrape or similar.

If I understand you correctly, this should get all the data between the tags:

Dim regex As New Text.RegularExpressions.Regex("<.*?>", RegexOptions.Singleline)
Dim result As String = regex.Replace(yourHtml, String.Empty)

You could use this to get just the H2 tags and data:

Dim regex As New Text.RegularExpressions.Regex("<\s*h2[^>]*>(.*?)<\s*/\s*h2>", RegexOptions.Singleline)
Dim results As New Text.StringBuilder
For Each m As Text.RegularExpressions.Match In regex.Matches(yourHtml)
    results.Append(m.Value)
Next
like image 199
alundy Avatar answered Aug 03 '26 23:08

alundy