cn.t.util.common.RegexUtil Maven / Gradle / Ivy
package cn.t.util.common;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexUtil {
private static final Pattern IP_MATCH_REG = Pattern.compile("^\\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b$");
private static final Pattern IP_REG = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
public static boolean isIp(String ip) {
Matcher matcher = IP_MATCH_REG.matcher(ip);
return matcher.find();
}
public static String getIp(String str) {
Matcher matcher = IP_REG.matcher(str);
if(matcher.find()) {
return matcher.group();
} else {
return null;
}
}
}