regular expression - parent domain only

Looking for a regex that will match the parent domain only.
in examples like the following
abcdefg.com   =  abcdefg.com
abcdefg.cn  =      abcdefg.cn
abc.def.org   =  def.org
abc-def.ghi.uk  = ghi.uk

This is the output of a cmdlet that won't produce any http:// prefix, nor any trailing pages - just the domain info, but I only want to extract the parent. Thanks!
LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

\w+\.\w+$

Open in new window

EDIT and for .co.uk or .co.jp

\w+\.(\w+|co\.\w{2})$

Open in new window

Regards
sirbountyAuthor Commented:
I don't know enough regex to know why it's not working, but it doesn't seem to be picking out that information.
I've tried both in powershell and regextester.com
Rgonzo1971Commented:
Don't understand it works in regextester.com

EE
how do you use it?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

sirbountyAuthor Commented:
I have these examples in regextester:

abc-def.ghi.uk
facebook.com
somewhere.somewhereelse.com
abcdefg.com
abcdefg.cn
abc.def.org


Should it highlight just one, or any matches?
I'll be pulling these from an array, if that matters?
sirbountyAuthor Commented:
If I take off the trailing $, it matches the def.ghi portion of this, but I would need ghi.uk from it...doesn't match anything with the $ left on.

abc-def.ghi.uk
sirbountyAuthor Commented:
Weird - same regex and test as your screen shot, but it fails on mine with the exact same data?

regextest.png
Rgonzo1971Commented:
Is there a space after org?
LearnctxEngineerCommented:
When you're trying to match TLD's and also catching country TLD's its a bit of a pain. I would use an exclusion match on the delimiter..

I've included all of the valid country TLD's (as per the Wikipedia article on the subject) and one with just the .uk TLD. I wouldn't use \w for the TLD as I don't think you'll find a TLD with a number in it.

UK TLD only
[\w-]+\.[a-zA-Z]+(\.uk)?$

Open in new window

All country TLD's
[\w-]+\.[a-zA-Z]+(\.(ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw))?$

Open in new window


If you are really keen you can probably go ahead and make sure that no rules are being broken like domain names starting, ending or containing multiple hyphens in sequence. Examples.

-bad-domain.com
bad--domain.com
baddomain-.com
-reallybaddomain-.com
good-domain.com

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
Thanks to you both
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.