Extracting a TLD from the content and assign to custom field

First, your return statement is before you actually add the meta data, so your hook is terminating before it can do that. Remember that return ends the function it’s within, so only put it at the very end or in places you want it to short-circuit.

Second, your RegEx is a little off; you shouldn’t be using the ^ and $ markers since you’re trying to match a domain name anywhere within the text.

Here’s a patter that may do the job:

/(?<=^|\/|\s)([\w\-\.]+\.\w+)(?=^|\/|\s)/

This will match bob.com, but not [email protected] because the (?<=) and (?=) bits tells it to only consider matches that are preceded/followed by the beginning/end of the string, a forward slash, or a whitespace character. You’ll probably need to play around with those lists to make sure it doesn’t accidentally grab something else, or miss a valid entry surrounded by other stuff like HTML.