biryu2205 / Biryu

0 stars 0 forks source link

Hackerrank String Regex #73

Closed biryu2205 closed 6 years ago

biryu2205 commented 7 years ago
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));
        }

    }
}
class MyRegex {
  private String part = "((25[0-5])|(2[0-4][0-9])|([0-1]{0,1}[0-9]{1,2}))";
  String pattern = String.format("%s\\.%s\\.%s\\.%s", part, part, part, part);
}