I have tried to make this example work in Java: Private IP Address Identifier in Regular Expression
I want to check if a IP is a private one, except 127.x.x.x
But I'm going to get crazy, What is wrong in this code?:
private static final Pattern patternPrivateNotLocal = Pattern.compile("(^10\\.)|(^172\\.1[6-9]\\.)|(^172\\.2[0-9]\\.)|(^172\\.3[0-1]\\.)|(^192\\.168\\.)");
public static boolean isPrivateAndNotLocalIP(String ip)
{
return patternPrivateNotLocal.matcher(ip).matches();
}
The method is returning me false
when ip = "192.168.122.1"