Pattern Syntax Checker

  • + 0 comments
            try{
                Pattern.compile(pattern);
                System.out.println("Valid");
            }
            catch (PatternSyntaxException pe){      //patternSytaxException Handled.
                System.out.println("Invalid");
            }
            testCases --;   //Reduce value by 1
        }
    
        // Note: In this problem, a regex is only valid if you can compile it using the Pattern.compile method.