Check url in java

Does anyone know how to check URL format in Java using regex?

thanks

+3
source share
2 answers

A very difficult way:

try { new java.net.URI(myUrl); } catch(URISyntaxException e) { // url badly formed } 
+7
source

You might be better off using the URI class in Java: http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html

It will throw an exception in the constructor if it doesn't parse correctly.

+7
source

All Articles