public class StringTest { public static void main(String[] args) { String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z"; String str1 = "1.1.1.0"; boolean flag1 = str1.matches(regex); System.out.println(flag1); String str2 = "222"; boolean flag2 = str2.matches(regex); System.out.println(flag2); } }
原文地址:https://www.cnblogs.com/zhanzhuang/p/10976838.html
时间: 2024-10-11 07:53:30