English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
자식 표현식/기본 문자 \ G ”와 마지막 매치의 끝 점과 일치합니다.
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { String regex = "\\G[0-9}"; Scanner sc = new Scanner(System.in); System.out.println("문자열을 입력하세요:"); String input = sc.nextLine(); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(input); int count = 0; String digits = ""; System.out.println("이전 경기의 숫자:"); while(m.find()) { System.out.print(m.group()); count ++; } System.out.println(); System.out.println("매치 수: ");+count); } }
출력 결과
문자열을 입력하세요: 555 sample text 이전 경기의 숫자: 555 매치 수: 3