public static void main(String[] args) {
String regex = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
System.out.println(IsMatch(url,regex));
}
private static boolean IsMatch(String s, String pattern) {
try {
Pattern patt = Pattern.compile(pattern);
Matcher matcher = patt.matcher(s);
return matcher.matches();
} catch (RuntimeException e) {
return false;
}
}
Javaで正規表現を使ってURLをチェック
めんどくさいのでクラスにした簡単なのがありました。
0 Comments until now.
Comment!