パターンの検索
トレンド分析のために、プラットフォームの世代別に販売データをグループ化する必要があります。プラットフォーム名からバージョン番号を抽出することで、コンソールの世代ごとに販売データを分類できます。ビデオゲームデータセットからいくつかのプラットフォーム名を抽出済みです。
CharMatcher や Pattern などの必要なパッケージはすでにインポートされています。
この演習はコースの一部です
Java によるデータクリーニング
演習の手順
matcherがバージョン番号を見つけられるか確認しましょう。matcherが見つけたバージョン番号を出力しましょう。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
public class PatternValidation {
public static void main(String[] args) {
List platforms = Arrays.asList("PlayStation 5", "PlayStation 4", "Xbox One", "Switch");
Pattern versionPattern = Pattern.compile("\\d"); // Match single digit versions
for (String platform : platforms) {
Matcher matcher = versionPattern.matcher(platform);
// Check if the matcher finds any version number
if (____.____()) {
// Report the version number that the matcher finds
System.out.println(platform + ": version " + ____.____());
} else {
System.out.println(platform + ": no version number");
}
}
}
}