不多说直接上代码
public static String ipRegex(String str){
if(str.matches("((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))")){
System.out.println("输入正确");
}else{
System.out.println("输入错误");
}
return str;
}