I want a way to capture the Top-Level Domain from a URL, but am not able to get any success. The problem in my case is that the URL can be different. Sometimes a user can enter www.google.com or m.google.com or m.google.uk or google.uk or www.m.google.com
I tried using slice
but it didn't work as I can have 2 or 3 characters in my URL. I can't split based on ".", I might get 2 or 3 or 4 results. Is there a single-line JavaScript function I can use? Is there any easy custom function available?
All posts are pointing to get the host name but in my case I want to extract just last 3 or 2 characters of the URL (com, uk, cn, etc.). I can apply multiple if-else loops too but I want to avoid that, and want to check if there is a simple solution for this.
I am looking for output as 'com' or 'uk' or 'cn' depending on top level domain of my URL. URL is entered by user which is why it difficult to predict if user will enter m.google.com or www.m.google.com or www.google.com or simply google.com