시작하기무료로 시작하기

Full pattern matching

You're preparing a historical analysis of game releases, but your database contains dates in mixed formats. Before you can analyze release timing patterns, you need to identify which dates need reformatting to match your standard MM/DD/YYYY format. You've extracted dates from the video game dataset below.

Game Platform Release date Quantity (millions of units)
Wii Sports Wii 11/19/2006 41.49
Super Mario Bros. NES 11/13/1985 29.08
Mario Kart Wii Wii 4/10/2008 15.85

The necessary packages such as Pattern, and Matcher have been imported for you.

이 연습은 강의의 일부입니다

Cleaning Data in Java

강의 보기

연습 안내

  • Define a regex pattern to match the date format d/MM/yyyy.
  • Check if the entire date string matches datePattern.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

public class PatternValidation {
    public static void main(String[] args) {
        List dates = Arrays.asList("11/19/2006", "11/13/1985", "4/10/2008", "2008-04-10");
        // Define a regex pattern to match the date format
        Pattern datePattern = ____.____("\\d{1,2}/\\d{1,2}/\\d{4}");

        for (String date : dates) {
            // Check if entire date string matches datePattern
            boolean isValid = datePattern.____(date).____();
            System.out.println(date + " is valid: " + isValid);
        }
    }
}
코드 편집 및 실행