Possible Duplicate:
Regex to match URL
Given a String, I want to know whether it represents a URL or not and get the website name, which is the “whatever”.
For example, given “http://google.com.sg” or “http://google.com.sg/“, I want to return String “google.com.sg”.
Is there a neat way of doing this in Java?
There are a number of ways of doing this, but a simple regular expression is quite error-prone. Best thing to do is to feed it to an existing parser and then use methods to pull out the bits that you need, for example