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);}}
如果觉得《Java正则表达式判断一个字符串是否是ipv4地址》对你有帮助,请点赞、收藏,并留下你的观点哦!