📅  最后修改于: 2022-03-11 14:52:33.910000             🧑  作者: Mango
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));
}
}
}
//YOU SHOULD ONLY SUBMIT THE FOLLOWING BLOCK
class MyRegex
{
String pattern =
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
}