Java Regex

  • + 0 comments

    import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Scanner;

    class Solution{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String IP = in.next();
            System.out.println(IP.matches(new MyRegex().pattern));
        }
    
    }
    

    } public class MyRegex { public static void main(String[] args) { MyRegex regex = new MyRegex(); Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            String ip = scanner.next();
            // Validate the IP against the regex pattern
            System.out.println(ip.matches(new MyRegex().pattern));
        }
    
        scanner.close();
    }
    

    }