I am trying to get the website name from the host url(e.g "www.google.com" -> google, "facebook.com" -> facebook) Currently I have this simple function:
private fun getWebsiteNameFromUri(host: String): String {
val cutString = host.substringBefore(".")
return cutString.substringAfter(".")
}
It doesn't work bad for many website, but of course there are MANY others that it's not working correctly, for example: "medium.com" just return com
I tried also count '.', and other approches but again, work for some and doesn't work for others.
There is any convention for extracting such a thing? If not, How can I extract the website name, heavy regex is the only option?