package com.dayou.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegxUtil {

    public static String findFirstMatchStr(String str,String regx){
        Pattern pattern = Pattern.compile(regx);

        Matcher m = pattern.matcher(str);

        if (m.find()) {
            return m.group(1);
        }
        return null;
    }

    /**
     * 是否非负整数
     * @param str
     * @return
     */
    public static boolean isNonNegativeInteger(String str){
        String regx="^\\d+$";
        return isMatch(str, regx);
    }

    public static boolean isMatch(String str,String regx){
        Pattern pattern = Pattern.compile(regx);

        Matcher m = pattern.matcher(str);
        return m.matches();
    }
}
