Get Domain Name from URL?

  • Thread starter Thread starter Jack
  • Start date Start date
Hello,

I need to get:

microsoft.com

From these possible string:

www.microsoft.com
http://www.microsoft.com
http://microsoft.com
microsoft.com
sql.microsoft.com
htttp://sql.microsoft.com

Regular Expressions is one way.

Imports System.Text.RegularExpressions
....
Dim rx As Regex = New Regex("(?<1>microsoft.com)")
Dim mt As Match = rx.Match("http://www.whatever.microsoft.com")
If mt.Success Then
retval = mt.Groups(1).ToString
End If

There's decent pattern matching help in MSDN and Google.

--

-shane

Shane Thomas
HSI [http://www.hsisoft.com]
 
Hello,

Thanks!! I also need it to work on any domain name and just return the
domainname.TopLevelDomain

Thanks,

Jack

Shane Thomas said:
Jack said:
Hello,

I need to get:

microsoft.com

From these possible string:

www.microsoft.com
http://www.microsoft.com
http://microsoft.com
microsoft.com
sql.microsoft.com
htttp://sql.microsoft.com

Regular Expressions is one way.

Imports System.Text.RegularExpressions
...
Dim rx As Regex = New Regex("(?<1>microsoft.com)")
Dim mt As Match = rx.Match("http://www.whatever.microsoft.com")
If mt.Success Then
retval = mt.Groups(1).ToString
End If

There's decent pattern matching help in MSDN and Google.

--

-shane

Shane Thomas
HSI [http://www.hsisoft.com]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top