// 정규식으로 아래 패턴을 파싱함. ex) xxx.xxx.xxx.xxx:26379 Pattern pattern = Pattern.compile("(\\d+.\\d+.\\d+.\\d+):(\\d+)"); // DNS Pattern ex) sentinel:26379 Pattern dnsPattern = Pattern.compile("(\\w+.*)+:(\\d+)"); for (String sentinelInfo : sentinelInfos) { Matcher matcher = pattern.matcher(sentinelInfo); if (matcher.find() && matcher.groupCount() == 2) { sentinelsSet.add(matcher.group(1) + ":" + Integer.parseInt(matcher.group(2))); } else { matcher = dnsPattern.matcher(sentinelInfo); if (matcher.find() && matcher.groupCount() == 2) { sentinelsSet.add(matcher.group(1) + ":" + Integer.parseInt(matcher.group(2))); } } } |