iP的正则表达式:^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]|[*])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]|[*])$
解释下
\d: 匹配1位 0-9
[1-9]\d: 匹配 2位 10-99
1\d\d: 匹配 3位 100 - 199
2[0-4]\d: 匹配 3位 200-249
25[0-5]: 匹配 3位 250-255
[*] : 匹配*
- /**
- * 判断是否是IP地址
- * @param str
- * @return
- */
- public static boolean isIPAdress( String str )
- {
- Pattern pattern = Pattern.compile( "^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$" );
- return pattern.matcher( str ).matches();
- }