public List<String> getIps(String ipString){ String regEx="((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"; List<String> ips = new ArrayList<String>(); Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(ipString); while (m.find()) { String result = m.group(); ips.add(result); } return ips; } public List<String> getIPAddressByRegex(String str) { List<String> ips = new ArrayList<String>(); String regex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"; if (str.matches(regex)) { String[] arr = str.split("\\."); for (int i = 0; i < 4; i++) { ips.add(arr[i]); } } return ips; }
java 字符串切分ip地址及ip地址字段的切分
最新推荐文章于 2023-02-14 21:12:32 发布