-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyntax_Checker.java
More file actions
24 lines (23 loc) · 890 Bytes
/
Syntax_Checker.java
File metadata and controls
24 lines (23 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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(); //enter the string..
//Write your code
try
{
Pattern.compile(pattern); //this method will take the input and check the regex is valid or not..if it gives an exception then it is not valid..
System.out.println("Valid");
}
catch (PatternSyntaxException p) //suppose the regex is not valid then the exception generated will be (PatternSyntaxException)...
{
System.out.println("Invalid"); //print invalid..
}
testCases--; //decreasing the value..
}
}
}