[java] 정규식 pattern, matcher
자바에서 종종 사용되는 정규식 메서드
@Test @DisplayName("정규식 학습") void patterMatcher() { String strings = "0111010"; Pattern pattern = Pattern.compile("0?[^0]+0?"); // 0P0, 0P, P0, P (P는 0 이외의 1개 이상 문자열) Matcher matcher = pattern.matcher(strings); // find : 매치되는 문자열이 있으면 true 반환 while (matcher.find()) { // group : 매치되는 문자열 반환 System.out.println("matcher.group() = " + matcher.group()); } }
최신 댓글