Added 14 solutions
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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());
|
||||
while (testCases > 0){
|
||||
String pattern = scan.nextLine();
|
||||
try {
|
||||
Pattern.compile(pattern);
|
||||
System.out.println("Valid");
|
||||
} catch (PatternSyntaxException exception) {
|
||||
System.out.println("Invalid");
|
||||
}
|
||||
}
|
||||
scan.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user