Files
HackerRank-Solutions/Java/Strings/Pattern Syntax Checker/Solution.java
T

24 lines
724 B
Java
Raw Normal View History

2017-02-09 02:12:38 -08:00
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/* If a PatternSyntaxException is not thrown by Pattern.compile,
then the regular expression is valid.
*/
public class Solution {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int testCases = Integer.parseInt(scan.nextLine());
2017-02-16 23:51:56 -06:00
while (testCases-- > 0){
2017-02-09 02:12:38 -08:00
String pattern = scan.nextLine();
try {
Pattern.compile(pattern);
System.out.println("Valid");
} catch (PatternSyntaxException exception) {
System.out.println("Invalid");
}
}
scan.close();
}
}