We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt(); // Number of test cases
sc.nextLine(); // Consume the newline character
for (int i = 0; i < testCases; i++) {
String pattern = sc.nextLine(); // Input regex pattern
try {
Pattern.compile(pattern); // Attempt to compile the pattern
System.out.println("Valid");
} catch (PatternSyntaxException e) {
System.out.println("Invalid");
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pattern Syntax Checker
You are viewing a single comment's thread. Return to all comments →
import java.util.Scanner; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException;
public class Solution {
}