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

26 lines
830 B
Java
Raw Normal View History

2017-03-10 01:10:37 -06:00
// Author: Rodney Shaghoulian
// Github: github.com/rshaghoulian
// HackerRank: hackerrank.com/rshaghoulian
2017-02-09 02:12:38 -08:00
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
2017-04-05 18:42:35 -05:00
// If a PatternSyntaxException is not thrown by Pattern.compile, the regular expresion is valid
2017-02-09 02:12:38 -08:00
public class Solution {
2017-04-05 18:42:35 -05:00
public static void main(String[] args) {
2017-02-09 02:12:38 -08:00
Scanner scan = new Scanner(System.in);
int testCases = Integer.parseInt(scan.nextLine());
2017-04-05 18:42:35 -05: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();
}
}