On the face of it, I was thinking a relatively straightforward regex split would do the job, but then of course it needed to know something about domain names, and specifically top level domain names, as there are country-to-country variations such as
something.fr
something.uk
something.co.uk
where you’d want the “something” to be included in the domain name.
I did find a forum post from 2015 but I didn’t make that work.
So I went in search of a list to provide the “knowledge” of top level and country-specific top level domains.
From this, we can extract a variation of domain suffixes and use that to derive the other parts of the address you require. (I think).
Anyway, the attached isn’t pretty, and is a little convoluted but it may help with the inspiration for you or others to shrink it down, or find better alternatives.