Posted on

Get Domain Name

define $GetDomainName(#domain) {
    set(#domainOut,$find regular expression(#domain,"\\w+\\.\\w+$"),"Local")
    if($text length($replace regular expression(#domainOut,"\\..*","")) <= 2) {
        then {
            set(#domainOut,$find regular expression(#domain,"\\w+\\.\\w+\\.\\w+$"),"Local")
        }
    }
    return(#domainOut)
}
alert($GetDomainName("test.mydomain.com"))
alert($GetDomainName("amazon.co.uk"))
alert($GetDomainName("shopping.amazon.co.uk"))