其他分享
首页 > 其他分享> > 正则表达式匹配IP地址

正则表达式匹配IP地址

作者:互联网

IP地址规则:

import java.util.regex.PatternSyntaxException;

/**
 * @Author:Liu
 * @Data:2021/2/20 15:51
 */
public class IP {
    public static void main(String[] args){
        String string = "202.199.13.64";
        boolean IsMatch = false;
        try {
           IsMatch = string.matches("(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))");
        } catch (PatternSyntaxException ex) {
        }
        if (IsMatch){
            System.out.println("Match!");
        }else {
            System.out.println("Not Match!");
        }

    }
}

 

标签:25,匹配,数字,正则表达式,System,IsMatch,IP地址,Match,string
来源: https://www.cnblogs.com/iuyy/p/14421645.html