File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Author: Atharv Damle
2
+ // Check if a regex (regular expression) is valid.
3
+ // Full Question: https://www.hackerrank.com/challenges/pattern-syntax-checker/problem
4
+
5
+ import java .util .Scanner ;
6
+ import java .util .regex .*;
7
+
8
+ public class PatternSyntaxChecker
9
+ {
10
+ public static void main (String [] args ){
11
+
12
+ Scanner in = new Scanner (System .in );
13
+
14
+ int testCases = Integer .parseInt (in .nextLine ());
15
+ while (testCases >0 ){
16
+
17
+ // Accept the pattern as input.
18
+ String pattern = in .nextLine ();
19
+ try
20
+ {
21
+ // Load the pattern. Try to create a Pattern object. If it fails, an error will be raised.
22
+ Pattern .compile (pattern );
23
+ System .out .println ("Valid" );
24
+ }
25
+ catch (Exception e )
26
+ {
27
+ System .out .println ("Invalid" );
28
+ }
29
+
30
+ testCases --;
31
+ }
32
+ }
33
+ }
34
+
35
+
36
+
You can’t perform that action at this time.
0 commit comments