I have a little program allowing users to type-in some regular expressions. afterwards I like to check if this input is a valid regex or not.
I\'m w
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);
}
catch(Exception e)
{
// System.out.println(e.toString());
System.out.println("Invalid");
}
System.out.println("Valid");
}
}
}