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

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

正则表达式工具类

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

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()             
关注
打赏
1665409997
查看更多评论
0.0414s