I am wondering if there is a parser or library in java for extracting the second level domain (SLD) in an URL - or failing that an algo or regex for doing the same. For exam
1.
Method nonePublicDomainParts from simbo1905 contribution should be corrected because of TLD that contain "."
, for example "com.ac"
:
input: "com.abc.com.ac"
output: "abc"
correct output is "com.abc"
.
To get SLD
you may cut TLD
from a given domain using method publicSuffix()
.
2.
A set should not be used because of domains that contain the same parts, for example:
input: part1.part2.part1.TLD
output: part1, part2
correct output is: part1, part2, part1
or in the form part1.part2.part1
So instead of Set
use List
.