标签:返回 oid 否则 main pattern log [] 0.12 rgs
每个ip数值为0-225 否则输出false,正确返回true
例如:输入:
000.12.12.034
121.234.12.12
23.45.12.56
00.12.123.123123.123
122.23
Hello.IP
输出为:
true true true false false false
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 { 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])$"; }
标签:返回 oid 否则 main pattern log [] 0.12 rgs
原文地址:http://www.cnblogs.com/Angella/p/6536314.html