Author Topic: C# Regular Expression to Removing Subdomains from a URL  (Read 8373 times)

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
C# Regular Expression to Removing Subdomains from a URL
« on: August 28, 2008, 09:27:47 AM »
Hello all,
if you need regular expression to remove all the subdomains from a url to leave only the domain name. e.g.

http://rss.abc.def.SiteName.com.edu.au

<after applying regex leave>

SiteName.com.edu.au

Then you can use the following:

Code: [Select]
Regex.Replace( mySiteUrl, ".*SiteName", "SiteName", RegexOptions.IgnoreCase );