Forum Moderators: open

Message Too Old, No Replies

C# Regular Expression to Removing Subdomains from a URL

Using C# regular expressions to obtain only the domain name

         

israr

12:33 pm on Jun 4, 2008 (gmt 0)

10+ Year Member



Hi all,

Can any body know regular expression to remove all the subdomains from a url to leave only the domain name. e.g.

[rss.abc.def.SiteName.com.edu.au...] <after applying regex leave>

SiteName.com.edu.au

Please note that in above example there are 3 subdomains, but this is not fixed. The domains could be anything from 0 to more.

Or some function that would do the job.(like Uri.DnsSafeHost, but this return 'rss.abc.def.SiteName.com.edu.au')

Thanks for help...

WesleyC

5:12 pm on Jun 9, 2008 (gmt 0)

10+ Year Member



Regex.Replace( mySiteUrl, ".*SiteName", "SiteName", RegexOptions.IgnoreCase );

israr

4:53 pm on Jun 12, 2008 (gmt 0)

10+ Year Member



Thanks WesleyC, just the result I wanted...