Pattern Syntax Checker

Sort by

recency

|

385 Discussions

|

  • + 0 comments

    import java.util.Scanner; import java.util.regex.; / * @Author : Rehan */ public class SolutionDump { 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();
            try{
                Pattern.compile(pattern);
                System.out.println("Valid");
            }catch(PatternSyntaxException e){
                System.out.println("Invalid");
            }
            testCases--; 
        }
        in.close();
    }
    

    }

  • + 0 comments

    import java.util.*; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
         int N = Integer.parseInt(sc.nextLine());
    
         for(int i=0;i<N;i++){
            String pattern = sc.nextLine();
            try {
                Pattern.compile(pattern); // Attempt to compile the pattern
                System.out.println("Valid");
            } catch (PatternSyntaxException e) {
                System.out.println("Invalid");
            }
        }
      }  
    }
    
  • + 0 comments
    public class Solution
    {
    	public static void main(String[] args){
    		Scanner in = new Scanner(System.in);
    		while(in.hasNextLine()){
    			String pattern = in.nextLine();
              	try{
                  Pattern.compile(pattern);
                  System.out.println("Valid");
                  }
                  catch(Exception e ){
                      System.out.println("Invalid");
    
              }
        }
        in.close();
    }
    

    }

  • + 0 comments

    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();

              try{
                  Pattern p = Pattern.compile(pattern);
                  System.out.println("Valid");
              }catch(Exception e){
                  System.out.println("Invalid");
              }
              testCases--;
        }
        in.close();
    }
    

    }

  • + 0 comments

    while(testCases>0){

            String pattern = in.nextLine();
            //Write your code
              try{
                  Pattern.compile(pattern);
                      System.out.println("Valid");
    
              }catch(PatternSyntaxException e){
                      System.out.println("Invalid");
                  }
                  testCases--;
        }