WORKS GREAT but thanks for the reply bretticus
I am sorry to inform you that it works quite badly if my ISP were to submit its web address for link exchange. www.starhub.net.sg becomes net.sg, not starhub.
Now, ".com" is not a "domain name extension", but rather is a top level domain. However, terminology aside, running your example (after fixing matches[0] to be $matches[0]) gives me "test.com", but you want "test", so clearly it does not work even with your test case.
I suggest using parse_url($url, PHP_URL_HOST) to get the domain name, and from there use regex to extract the part that you want, keeping in mind that some domain names have a country specific top level domain, and yet have a generic domain at the second level.