- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyntax_Checker.java
More file actions
Latest commit
24 lines (23 loc) · 890 Bytes
/
Copy pathSyntax_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
importjava.util.Scanner;
importjava.util.regex.*;
publicclassSolution
{
publicstaticvoidmain(String[] args){
Scannerin = newScanner(System.in);
inttestCases = Integer.parseInt(in.nextLine());
while(testCases>0){
Stringpattern = 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 (PatternSyntaxExceptionp) //suppose the regex is not valid then the exception generated will be (PatternSyntaxException)...
{
System.out.println("Invalid"); //print invalid..
}
testCases--; //decreasing the value..
}
}
}