TLDExtractor 1.0.2

Suggested Alternatives

TLDExtract.url

dotnet add package TLDExtractor --version 1.0.2
                    
NuGet\Install-Package TLDExtractor -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TLDExtractor" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TLDExtractor" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TLDExtractor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TLDExtractor --version 1.0.2
                    
#r "nuget: TLDExtractor, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TLDExtractor@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TLDExtractor&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TLDExtractor&version=1.0.2
                    
Install as a Cake Tool

TLDExtractor Codacy Badge

C# Library

TLDExtractor is similar to tldextract library (in Python). By using TLDExtractor, you can accurately extract subdomain, domain, and domain suffix (effective TLD) of a given domain name.

It is a common mistake to split a domain name with '.' character and consider the last part as a domain suffix. For example, consider 'www.yahoo.co.uk', in this domain, 'co.uk' is the suffix not 'uk'.

TLDExtractor utilize the Public Suffix List to correctly identify the suffix for a given domain name. To extract subdomain, domain, and domain suffix, you can use TLDExtractor.Extract methods:

var result = TLDExtractor.Extract("www.yahoo.co.uk");
// result.ToString() -> 
//    {ExtractResult(subdomain='www', domain='yahoo', suffix='co.uk', suffix type='ICANN')}

// nom.ae is a private suffix submitted by Dave McCormack <dave.mccormack@nymnom.com>
var result = TLDExtractor.Extract("www.test.nom.ae");
// result.ToString() -> 
//    {ExtractResult(subdomain='www', domain='test', suffix='nom.ae', suffix type='Private')}

// you can pass a Uri
Uri guestUrl = new Uri("http://www.example.com/mine.html");
var result = TLDExtractor.Extract(guestUrl);
// result.ToString() -> 
//    {ExtractResult(subdomain='www', domain='example', suffix='com', suffix type='ICANN')}

If the domain name is not valid, TLDExtractor.Extract raises TLDExtractorException with an appropriate message explaining the problem. According to RFC 1035, domain names must be equal or less than 255 characters, and each label such as yahoo or www must be equal or less than 63 characters. Moreover, domain labels cannot be empty. For example, test..com is not valid.

In addition to TLDExtractor.Extract method, you can use TLDExtractor.TryExtract method to extract domain parts from a domain or URL, the only difference these two is that TLDExtractor.TryExtract does not raise any TLDExtractorException exception. It returns false if the given domain name is not a valid one.

ExtractResult result;
bool isExtracted = TLDExtractor.TryExtract("www.yahoo.co.uk", out result);

if(isExtracted)
{
    // do something
}
else
{
    // something went wrong
}

By default, TLDExtractor downloads the Public Suffix List from the Internet if it doesn't exist in the working directory or it is too old (it is created more than 30 days). You can override these default values by

TLDExtractor.SuffixListFilePath = "change_the_default_file_name.txt";

TLDExtractor.RenewAfterNDays = 60; 

TLDExtractor.RenewAfterNDays = -1; // to disable renewal mechanism
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 413 10/22/2025 1.0.2 is deprecated because it is no longer maintained.
1.0.1 379 10/21/2025 1.0.1 is deprecated because it is no longer maintained.