Java examples for java.util.regex:Match IP Address
is Ip address by Regex
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static final String IPADDRESS = "((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))"; public static boolean isIpaddress(String str) { return Regular(str, IPADDRESS); }//from w ww . ja va2s. c om 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(); } }