0

I need to output "Exceptional Innovation"

<div id="basic-info">
<h1 class="fn org">
<span>
Exceptional Innovation
</span>

Here's my Code

RichTextBox1.Text = htmlsource



        Dim myMatch As New System.Text.RegularExpressions.Regex("(?<=<div id=""basic-info""> <h1 class=""fn org""> <span>).+?(?<=</span>)", RegexOptions.IgnoreCase Or RegexOptions.Compiled)
        Dim matches As MatchCollection = myMatch.Matches(RichTextBox1.Text)

        For Each itemcode As Match In matches
            Dim output As String = (itemcode.Value.Split("""").GetValue(0))
            MsgBox(output)
        Next

Could somebody help me?

It works fine if I do something like this

Dim strsample = "345wq3453q245fgxh<div id=""basic-info""><h1 class=""fn org""><span>Exceptional Innovation</span>34535345345"




        Dim myMatch As New System.Text.RegularExpressions.Regex("(?<=<div id=""basic-info""> <h1 class=""fn org""> <span>).+?(?<=</span>)", RegexOptions.IgnoreCase Or RegexOptions.Compiled)
        Dim matches As MatchCollection = myMatch.Matches(strsample)

        For Each itemcode As Match In matches
            Dim output As String = (itemcode.Value.Split("""").GetValue(0))
            MsgBox(output)
        Next

But when I use the top most code I'm lost. Is there something wrong with my code or in the html source?

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by TechSupportGeek
0

My solution is done in a Console app, but same logic applies to a WinForms app as well. If that isn't quite what you're looking for, please let me know so I can further assist you.

Module Module1

    Sub Main()
        Dim strsample As String = "<span>Exceptional Innovation</span>" 'Example string to get value from
        Dim openTag As String = "<span>", closeTag As String = "</span>" 'Create strings which store tags
        Dim index As Integer = strsample.IndexOf(openTag) 'Get index of the opening tag
        Dim index2 As Integer = strsample.IndexOf(closeTag) 'Get index of the closing tag
        Dim output As String = strsample.Substring(index + openTag.Length, 
index2 - index - openTag.Length) 'Get value between tags
        Console.WriteLine(output) 'I did this as a Console app so I output the result to the command line
        Console.ReadLine() 'Keep program open until return key is pressed
    End Sub

End Module
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.