# 正则表达式篇

xiaoxiao2021-02-28  16

String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."

+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\$";

String regex ="^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)"+

":([0-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-5]{2}[0-3][0-5])\$"；

String regex="^\\d{3}-?\\d{8}|\\d{4}-?\\d{8}\$";

String regex=“\\w+@\\w+(\\.\\w{2,3})*\\.\\w{2,3}”;

pubilc String  public String ipCheck(String text) {

if(text!=null&&!text.isEmpty()){

String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."                    + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."

+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\$";

if(text.matches(regex)){

return text + "\n是一个合法的IP地址！";

}

else{

return text + "\n不是一个合法的IP地址！";

}

}

return "请输入要验证的IP地址！";

}