java determine whether the correct ip address regular expression

java regular expressions to determine whether the correct ip address

public class ClassWork05 {
    public static void main(String[] args) {
        System.out.println(IsIp.isIp("10.10.1.1"));
    }
}
class IsIp{
    public static boolean isIp(String ip) {
        boolean b1 = ip.matches("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}");
        return b1;
    }
}

//  输出结果为 true

This figure can be understood by ip address regular expression:

The ip java regular expression
([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}

Guess you like

Origin www.cnblogs.com/zhiwenxi/p/11361340.html