Regex for URL parsing

rosa545
rosa545 used Ask the Experts™
on
I want to make a regex to get all the url of the web page visited any helps that could work on all sites from search engines to any other visited website
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
i worked out the code but the issue is that it keeps on adding to old links how can i update the textbox with new source each time???


Dim pattern As String = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"

        Dim pattern1 As New System.Text.RegularExpressions.Regex(pattern)

        Dim m As MatchCollection = pattern1.Matches(TextBox1.Text)


        For Each link As Match In m   
                ListBox1.Items.Add(link)

    Next

Textbox1.text=webbrowser1.documenttext

Open in new window

What do you mean by adding new source?

Author

Commented:
see when i load page one it source gets into text box and adds links to listbox1

then when i navigate to another page the html source does not goes to textbox 1 and the links get added in listbox1 that are already been there
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
how can i update the textbox with new source each time???
Track the matches you've already seen:
Dim pattern As String = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"
Dim pattern1 As New System.Text.RegularExpressions.Regex(pattern)
Dim m As MatchCollection = pattern1.Matches(TextBox1.Text)
Dim priors As New List(Of String)

For Each link As Match In m
    If Not priors.Contains(link.Value) Then
        ListBox1.Items.Add(link)
        priors.Add(link.Value)
    End If
Next

Textbox1.text=webbrowser1.documenttext

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial