Java examples for java.util.regex:Match URL
is Url by Regex
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static final String URL = "^(http|www|ftp|)?(://)?(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*((:\\d+)?)(/(\\w+(-\\w+)*))*(\\.?(\\w)*)(\\?)?" + "(((\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*(\\w*%)*(\\w*\\?)*" + "(\\w*:)*(\\w*\\+)*(\\w*\\.)*" + "(\\w*&)*(\\w*-)*(\\w*=)*)*(\\w*)*)$"; public static boolean isUrl(String str) { return Regular(str, URL); }//w w w . j ava2 s .c o m private static boolean Regular(String str, String pattern) { if (null == str || str.trim().length() <= 0) return false; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(str); return m.matches(); } }