If you are given "http://foo.bar.abc.com" do you want to extract "foo" or "foo.bar"?
Either way, you can do this with just
string manipulation. No regex necessary. Just do a
substring.
You just need to find the right indices to pass in, and String has plenty of methods to figure those out.