polas anderson

polas anderson

  • NA
  • 3
  • 8.1k

how to match domain url using regex vb.net

Oct 4 2013 3:29 AM
I need to parse the url domain name from a string. The string can vary and I need the exact url domain.
If i type free web hosting i want to match correctly domain url.

Remove anything that does not match my domain url.

Just correct url from string using button, listbox and textbox

I do not wanna add like google.com,facebook.com bla bla bla in the listbox just correct matching domain url when i type from keyword.

i want like this www.webhosting.com
Remove www.webhosting.com/blablabla in the end of tring

I do not want only domain text i need url not the name of domain.
Remain only mathing urls.
Remove url junks.

This is what i got for so far.

http(s?)://([\w]+\.){0}([\w]+\.?)+

Add to this code.



Dim wc As New WebClient
        Dim source As String = wc.DownloadString("http://www.google.com/search?num=100&q=" + TextBox1.Text)
        Dim m1 As MatchCollection = Regex.Matches(source, "http(s?)://([\w]+\.){0}([\w]+\.?)+", RegexOptions.Singleline Or RegexOptions.IgnoreCase Or RegexOptions.Compiled)
        For Each m As Match In m1
            If Not m.Value.Contains("google") Then
                Dim value As String = m.Groups(0).Value
                ListBox1.Items.Add(value & vbCrLf)
                Label1.Text = ListBox1.Items.Count
            End If
        Next

Answers (1)