I don’t think it is that easy. If it was a case of including the www or other sub-domain, then it is very straight forward. But the complexity comes in when you start considering the domain name extension as well as an optional sub-domain being included.
Here’s some simple examples of some URLs and the expected text part of the link results.
Those are all real domain name extensions after my forum ID. There are well over 8,000 currently and it continues to grow, and they seem to vary between one and three dotted components in length.
I think you actually need to match the domain name extension, then track back one period separated string before that, and return that combination.
Now you could be thorough and iterate over all 8k+ domain name extensions, or you could perhaps whittle it down to the ones you are most likely to come across/use, which would improve the performance substantially I suspect
But, if it were okay to return the sub domain as well, then it’s just splitting the URL by forward slashes an taking the third element.
Why do you say the domain is the third element? Wouldn’t it be the second element? http:// is the first element; you’ll throw that away.
The domain is the next element, ending in the TLD.
Then throw away the next / and everything to the right of that.
@agiletortoise My regex skills are very, very bad. Hence my query here! Suppose I could learn but I thought there might be something lying around that would work, or that some regex genius could whomp something together in a minute.
This regex101 demo is pretty naive but is a basic pattern that would work for most cases, and you end up with the full URL in the full match and $2 would contain the domain for use in the substitution.
I’m about to go out so don’t have time to stick it in an action, but it’s a start.