All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.t.util.common.RegexUtil Maven / Gradle / Ivy

There is a newer version: 1.0.16.RELEASE
Show newest version
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;
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy