-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwentyFive.java
More file actions
26 lines (23 loc) · 781 Bytes
/
TwentyFive.java
File metadata and controls
26 lines (23 loc) · 781 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
25
26
// Here's the complete code that checks whether the given regex pattern is valid by attempting to compile it using Pattern.compile():
package HackerRank;
import java.util.Scanner;
import java.util.regex.*;
public class TwentyFive {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
if(!in.hasNextLine())
return;
int testCases = Integer.parseInt(in.nextLine());
while(testCases>0 && in.hasNextLine()){
String pattern = in.nextLine();
//Write your code
try {
Pattern.compile(pattern);
System.out.println("Valid");
} catch (PatternSyntaxException e) {
System.out.println("Invalid");
}
}
in.close();
}
}