[Java] – Regular expression to match IPv4 address

I saw such question on SO. There was no solution with RegEx so… I was bored I think.

public static boolean isValid(String ip) {
    boolean isvalid;
 
    isvalid = ip.matches(
            "(([0-9]|[0-9]{0,2}|1[0-9]*{0,2}|2[0-5][0-5]|0{0,3}).){3}" +
             "([0-9]|[0-9]{0,2}|1[0-9]*{0,2}|2[0-5][0-5]|0{0,3})"
    );
 
    return isvalid;
}

The regex was tested on the following addresses:

    String[] ips = {
        "0.0.0.0",
        "0.111.222.0",
        "0.0.0.000",
        "0.00.0.000",
        "1.1.1.1",
        "2.2.2.2",
        "12.13.14.15",
        "29.29.29.29",
        "99.99.000.1",
        "111.102.144.190",
        "255.255.199.199",
        "266.255.255.255", //inv
        "255.265.255.255", //inv 
        "255.255.258.255", //inv 
        "255.255.255.259", //inv 
        "299.100.110.255" //inv
    };
    for (String s : ips) {
        if (isValid(s) == false) {
            System.err.println(s + " is invalid");
        }
    }
[Total: 0    Average: 0/5]