polas anderson

polas anderson

  • NA
  • 13
  • 4.4k

how to extract top level domain url using regex in vb.net

Apr 10 2017 4:17 PM
I need to extract the extact top level domain url 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 top level domain url like this http://www.c-sharpcorner.com and so on...

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.anydomainname.com
Remove www.anydomainname.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 that there is not top level domain url.
This is for so far i have...
This code extract only domain name but not top level... http(s?)://([\w]+\.){0}([\w]+\.?)+
I need to be extracted only top level domain name...
How to do that ?
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

Thank you so much for any help.

Answers (1)