How to trim URL to root domain?

@AkshayHallur, since @Tom stepped out with a full solution, he inspired me to work on the RegEx.

I found a two-step solution that should work with ANY TDL, and any Server (like "www" or "test", or none).

First RegEx to Extract Server Name:
(I started with @Tom's RegEx)
^(?:.*:\/\/)?([^:\/]*).*$

See regex101: build, test, and debug regex

Second RegEx to Extract Domain Name from Server Name:
[^\.]+\.[^\.]+$

See regex101: build, test, and debug regex

Example Output

Given this URL: https://server1.google.somelongTDL/xyz

Here's the macro:

##Macro Library   @RegEx Extract Domain Name [Example]


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/2/2837417161ccf5c0db822e7a9ed602419a281562.kmmacros">@RegEx Extract Domain Name [Example].kmmacros</a> (3.3 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---


<img src="/uploads/default/original/2X/1/1b012163fa9c81df2bf4e913d944c9452902bf34.png" width="459" height="873">
2 Likes