String rexp = "^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$";
Pattern pat = Pattern.compile(rexp);
Matcher mat = pat.matcher("192.168.9.156");
boolean istrue=mat.find();
转载于:https://my.oschina.net/huhaoren/blog/392782