您当前的位置: 首页 >  正则表达式

正则表达式工具类

梁云亮 发布时间:2021-04-29 19:51:05 ,浏览量:3

public class RegexUtil {


    /**
     * 返回所有匹配到的内容
     *
     * @param regex 正则表达式字符串
     * @param str   要匹配的字符串
     * @return
     */
    public static List group(String str, String regex) {
        if (null == str || null == regex) {
            return null;
        }
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        List list = new LinkedList();
        while (matcher.find()) {
            list.add(matcher.group());
        }
        return list;
    }

    /**
     * 存在匹配
     *
     * @param str
     * @param regex
     * @return
     */
    private static boolean find(String str, String regex) {
        if (null == str || str.trim().length()             
关注
打赏
1688896170
查看更多评论
0.0709s