Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/dcee7d3b2d6e47dcd0afac58b8a8a35c to your computer and use it in GitHub Desktop.
Save MinSomai/dcee7d3b2d6e47dcd0afac58b8a8a35c to your computer and use it in GitHub Desktop.
Java | Pattern Syntax Checker - Hackerrank.java
import java.util.Scanner;
import java.util.regex.*;
public class Solution
{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int testCases = Integer.parseInt(in.nextLine());
while(testCases>0){
String pattern = in.nextLine();
try{
Pattern.compile(pattern);
System.out.println("Valid");
}catch(Exception ignore){
System.out.println("Invalid");
}
testCases--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment