@@ -0,0 +1,1488 @@
+package java_problems.strings;%0D%0A%0D%0Aimport java.util.regex.*;%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * Using Regex, we can easily match or search for patterns in a text. Before%0D%0A * searching for a pattern, we have to specify one using some well-defined%0D%0A * syntax.%0D%0A * %0D%0A * In this problem, you are given a pattern. You have to check whether the%0D%0A * syntax of the given pattern is valid.%0D%0A * %0D%0A * Note: In this problem, a regex is only valid if you can compile it using the%0D%0A * Pattern.compile method.%0D%0A * %0D%0A * Input Format: %0D%0A * The first line of input contains an integer N, denoting the number of%0D%0A * testcases. The next N lines contain a string of any printable characters%0D%0A * representing the pattern of a regex.%0D%0A * %0D%0A * Output Format: %0D%0A * For each testcase, print %22Valid%22 if the syntax of the given pattern is%0D%0A * correct. Otherwise, print %22Invalid%22. Do not print the quotes.%0D%0A * %0D%0A * Sample Input: %0D%0A * 3%0D%0A * (%5BA-Z%5D)(.+)%0D%0A * %5BAZ%5Ba-z%5D(a-z)%0D%0A * batcatpat(nat%0D%0A * %0D%0A * Sample Output: %0D%0A * Valid%0D%0A * Invalid%0D%0A * Invalid%0D%0A */%0D%0Apublic class PatternSyntaxChecker %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%0D%0A%09%09Scanner in = new Scanner(System.in);%0D%0A%09%09int testCases = Integer.parseInt(in.nextLine());%0D%0A%09%09while (testCases %3E 0) %7B%0D%0A%09%09%09String pattern = in.nextLine();%0D%0A%09%09%09try %7B%0D%0A%09%09%09%09Pattern.compile(pattern);%0D%0A%09%09%09%09System.out.println(%22Valid%22);%0D%0A%09%09%09%7D catch (PatternSyntaxException e) %7B%0D%0A%09%09%09%09System.out.println(%22Invalid%22);%0D%0A%09%09%09%7D%0D%0A%09%09%09testCases--;%0D%0A%09%09%7D%0D%0A%09%09in.close();%0D%0A%09%7D%0D%0A%7D

Add PatternSyntaxChecker