以下的代碼是關於Java檢測給定的IP地址是否合法的代碼。ide
public static boolean isIpAddress(String address){ String regex = "(((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.](((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.]" + "(((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.](((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(address); return m.matches(); }