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

27 lines
866 B
Java
Raw Normal View History

2017-03-10 01:10:37 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-03-10 01:10:37 -06:00
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);
2017-09-11 09:32:17 -07:00
int testCases = scan.nextInt();
scan.nextLine(); // gets rid of the pesky newline.
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();
}
}