java 正则表达式匹配

 

public class AA {
        public static void main(String[]args){
            String url="http://sss//222/detail/10105";
            String pattern = ".*/\\d+";
            boolean isMatch = Pattern.matches(pattern, url);
            System.out.println("是否符合:" + isMatch);

            Pattern p=Pattern.compile("\\d+");
            Matcher m=p.matcher(url);
            while(m.find()) {
                System.err.println("获取正则表达式匹配到的结果:" + m.group());
                url = url.replace(m.group(),"数字");
            }
            System.err.println("" + url);
        }
}

 

posted @ 2021-07-23 17:29  君子笑而不语  阅读(212)  评论(0编辑  收藏  举报