标签:java 正则
java正则匹配IP号码段
public static boolean IPMatch(List ips, String ip) { if (ips.contains(ip)) { return true; } for (int i = 0; i < ips.size(); i++) { List lip = Arrays.asList(ips.get(i).toString().split("\\.")); String re = "^"; for (int j = 0; j < lip.size(); j++) { String num = lip.get(j).toString(); if (num != "*") { re += num + "."; } else { re += "\\d{0,3}."; } if (j == lip.size()) { re = re.substring(0, re.length() - 1).toString() + "\\$"; } } Pattern pattern = Pattern.compile(re); Matcher matcher = pattern.matcher(ip); if (matcher.matches()) { return true; } } return false; }
标签:java 正则
原文地址:http://blog.csdn.net/zimu002/article/details/42965775