정규 표현식 연습
15 또는 18 자리 중 하나가, 마지막 편지가 될 수 있으며, 프로그램의 날짜를 작성하는 그들에게 물었다 : 정체성을 결정합니다.
길이; 내가 ++) { 매처 정합 = regular.matcher (strs [I ]) //는 정규의 생성 ( "ID를")를 sb.append; sb.append (STRs [I]); sb.append ( "매치") SB를 으로 .Append (matcher.matches ()) 에서 System.out.println (sb.toString ()); sb.delete (0 sb.length ()); // 삭제 방법의 StringBuilder } GetBirthDay (STRs) } 개인 GetBirthDay 정적 (문자열 [] STRs)를 무효 { 에서 System.out.println는 ( "출생의 날짜를 얻을 준비"); // 유효성 검사 준비는 규칙 패턴 BirthDayRegular =는 Pattern.compile ( "(\\의 D {6}) (\\ D {8}) (*) ");. // * 함께 수단의 수는 줄 바꿈 문자가 포함되어 있지 않습니다. 패턴을 패턴 = YearMonthDayRegular .compile ( "\\ (D {4}) (\\의 D {2}) (\\ D {2})"); 대해 INT (I = 0; I는 <strs.length; 나는 ++) { 매처 정합 = BirthDayRegular.matcher (strs [I]); 경우 (matcher.matches ()) { Matcher를 matcher2 = YearMonthDayRegular .matcher (matcher.group (2)); 경우 (matcher2.matches ()) { 에서 System.out.println (strs [I]는 + "中的出生年月分解为"+ "年」matcher2.group + (1) +"月" + matcher2.group (2) + "日"+ matcher2.group (3)); } } } }