正则表达式

String input = "ABCD1234BCDE";
        String mode = "BCD";

        Pattern pattern = Pattern.compile(mode);
        int count = 0;
        Matcher matcher = pattern.matcher(input);
        while(matcher.find()) {
            count++;
        }

匹配到两次就会退出while循环

注意不能这么写,这么写永远退不出来

while(pattern.matcher(input).find()) {
            count++;
        }

 

判断字符串里有没有点,以及用点来进行切分注意写法

if (code.contains(".")) {//不是正则
                String[] nums = code.split("\\.");//是正则

 

posted on 2021-12-29 10:59  MaXianZhe  阅读(12)  评论(0编辑  收藏  举报

导航