开发者

Determine if string is a URL with Regex in Java [duplicate]

This question already has answers here: Closed 11 years ago.

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜