ip网段或ip正则
@Test
public void ipTest() {
Pattern pattern = Pattern.compile("^(((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([1-9]|[1-2]\\d|3[0-2]))|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$");
System.out.println(pattern.matcher("192.168.3.5").matches());
System.out.println(pattern.matcher("192.168.3.5/16").matches());
}
运行结果
D:\environment\jdk\bin\java.exe
true
true
Process finished with exit code 0