Need regex (PCRE) for parsing root domains

Posted on 2011-10-09
Last Modified: 2012-05-12
I am looking for a regular expression for a php script to parse root domain from a given string with a 3 character TLD. For example,

should all return It should also work with other TLDs like .net, .org etc.

Question by:hvs69
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    How about:


    Open in new window

    LVL 74

    Expert Comment

    by:käµfm³d 👽


    Open in new window

    LVL 34

    Accepted Solution

    If you want to use the IANA official list of TLDs (which will include 2 part TLDs like, there's good info in this article on how to do it:

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now