regex - extract domain name and TLD
I'm trying to extract domain name and TLD (if it exists) from a string.
For "testing.co.uk" I want to have an array with values: ("testing", "co.uk")
For "-testing.c" I want to have an array with a value: ("testing")
For "test-ing.co.uk.com" I want to have an array with values ("test-ing","co.uk")

Rules are simple:
- first and last character of the domain name can't be "-"
- TLD has to have at least two characters
- TLD part may have one dot character "." but only if it's followed by at least two letters

I have this:
(\w[-\w]*\w) - First part that extracts the domain name (Working)
\.(\w{2,}(\.?\w{2,})?) - This is the part I can't get to work (not working)
regex - extract domain name and TLD
===

I'm trying to extract domain name and TLD (if it exists) from a string.
For "testing.co.uk" I want to have an array with values: ("testing", "co.uk")
For "-testing.c" I want to have an array with a value: ("testing")
For "test-ing.co.uk.com" I want to have an array with values ("test-ing","co.uk")

Rules are simple:
- first and last character of the domain name can't be "-"
- TLD has to have at least two characters
- TLD part may have one dot character "." but only if it's followed by at least two letters

I have this:
(\w[-\w]*\w) - First part that extracts the domain name (Working)
\.(\w{2,}(\.?\w{2,})?) - This is the part I can't get to work (not working)