Determine if string is a URL with Regex in Java [duplicate]
Possible Duplicates:
What is the best regular expression to check if a string is a valid URL Java-How to detect the presence of URL in a string.开发者_StackOverflow
Is there a way to see if a string is a valid URL? I'm using MIDP library and there are not regular expressions in MIDP. Any help is greatly appreciated.
Why not just construct a java.net.URL
out of the string and catch any exceptions that might be thrown?
String something;
try {
URL url = new URL(something);
} catch (MalformedURLException e) {
// it wasn't a URL
}
精彩评论