extract domain from URL
-
Hi guys. I'm going crazy from searching the Internet for solutions. how do i extract the domain from a URL or Uri the host name (
Uri.Host
) is not good enough since i want to remove all sub-domains. i found a few regex solutions but all are for single top level domains like .com, .org and .net but i need a solutions for co.uk and all domain types. I'm creating a app that allows browsing for certain domains that the user could choose, the user could add "*.google.co.uk" to allow all sub-domains of google.co.uk but i can't compare "search.something.google.co.uk" to match "*.google.co.uk" since i can't extract the domain only. Please if any one knows a solutions for this, or how to compare a host to a wildcard domain please reply. Thanks -
Hi guys. I'm going crazy from searching the Internet for solutions. how do i extract the domain from a URL or Uri the host name (
Uri.Host
) is not good enough since i want to remove all sub-domains. i found a few regex solutions but all are for single top level domains like .com, .org and .net but i need a solutions for co.uk and all domain types. I'm creating a app that allows browsing for certain domains that the user could choose, the user could add "*.google.co.uk" to allow all sub-domains of google.co.uk but i can't compare "search.something.google.co.uk" to match "*.google.co.uk" since i can't extract the domain only. Please if any one knows a solutions for this, or how to compare a host to a wildcard domain please reply. ThanksIM not sure how the Uri.Host string displays or the different types of addresses you could get, so i cant suggest a methofd for parsing. But you could split the string with '.' and then loop the results for a match to pre-defined values. i.e. if one value is 'Google' then its a google website etc. Again im not sure how reliable this would be but it could be a temp solution till you find a better way
-
IM not sure how the Uri.Host string displays or the different types of addresses you could get, so i cant suggest a methofd for parsing. But you could split the string with '.' and then loop the results for a match to pre-defined values. i.e. if one value is 'Google' then its a google website etc. Again im not sure how reliable this would be but it could be a temp solution till you find a better way
i still need a solution
-
i still need a solution
-
OK then: make a list of all '.com' '.co.uk' (whatever you call them) in the world. then search your uri for a match and the domain should be the split before the '.com' etc Thats a solution, right?
-
Hi guys. I'm going crazy from searching the Internet for solutions. how do i extract the domain from a URL or Uri the host name (
Uri.Host
) is not good enough since i want to remove all sub-domains. i found a few regex solutions but all are for single top level domains like .com, .org and .net but i need a solutions for co.uk and all domain types. I'm creating a app that allows browsing for certain domains that the user could choose, the user could add "*.google.co.uk" to allow all sub-domains of google.co.uk but i can't compare "search.something.google.co.uk" to match "*.google.co.uk" since i can't extract the domain only. Please if any one knows a solutions for this, or how to compare a host to a wildcard domain please reply. ThanksGetting the domain name from the host name is easy. It's just the two last keywords separated by a period. Except for the .co.uk domains of course... (Are there any other weird domains like this in the system?) Why not create a regular expression from the wildcard string by replacing * with .+? and encoding the rest? That would even give greater flexibility, as the user could search for something like "www.*.google.com".
Despite everything, the person most likely to be fooling you next is yourself.
-
@musefan .com etc are known as top-level domains.
-
i still need a solution
This isn't hard at all...
string url = "http://abc.com/default.aspx";
string[] parts = url.Split("//");
string[] parts2 = parts[1].Split("/");
string domain = parts2[0];If you need to further parse this, just do
domain.Split('.');
and take the first two array items, and you get the root domain. All you have to do is *think*."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Getting the domain name from the host name is easy. It's just the two last keywords separated by a period. Except for the .co.uk domains of course... (Are there any other weird domains like this in the system?) Why not create a regular expression from the wildcard string by replacing * with .+? and encoding the rest? That would even give greater flexibility, as the user could search for something like "www.*.google.com".
Despite everything, the person most likely to be fooling you next is yourself.
that is the answer i was looking for thanks
-
Hi guys. I'm going crazy from searching the Internet for solutions. how do i extract the domain from a URL or Uri the host name (
Uri.Host
) is not good enough since i want to remove all sub-domains. i found a few regex solutions but all are for single top level domains like .com, .org and .net but i need a solutions for co.uk and all domain types. I'm creating a app that allows browsing for certain domains that the user could choose, the user could add "*.google.co.uk" to allow all sub-domains of google.co.uk but i can't compare "search.something.google.co.uk" to match "*.google.co.uk" since i can't extract the domain only. Please if any one knows a solutions for this, or how to compare a host to a wildcard domain please reply. Thanks