I would like to check URL Validation in JAVA with regular-expression. I found this comment and I tried to use it in my code as follow...
private static final String PATTERN_URL = "/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/";
.....
if (!urlString.matches(PATTERN_URL)) {
System.err.println("Invalid URL");
return false;
}
But I got compile time exception for writing my PATTERN_URL
variable. I have no idea how to format it and I am worried about will it become invalid regex if I have modified. Can anyone fix it for me without losing original ? Thanks for your helps.