Pattern Syntax Checker

  • + 0 comments
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int cnt = scan.nextInt();
        scan.nextLine();
        for (int i = 0; i < cnt; i++){
            try{
                Pattern.compile(scan.nextLine());
            } catch (Exception e){
                System.out.println("Invalid");
                continue;
            }
            System.out.println("Valid");
        }
        scan.close();
    }