In this HackerRank Java Syntax Checker problem Java, you are given a pattern. You have to check whether the syntax of the given pattern is valid.

HackerRank Pattern Syntax Checker in java problem solution

 HackerRank Pattern Syntax Checker in java problem solution

import java.util.Scanner;
import java.util.regex.*;

public class Solution
{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int testCases = Integer.parseInt(in.nextLine());
        while(testCases>0){
            String pattern = in.nextLine();
            testCases--;
            try{
                Pattern.compile(pattern);
                System.out.println("Valid");
            }catch(PatternSyntaxException ex){
                System.out.println("Invalid");
            }
        }
    }
}