JAVA 正则表达式

 

        String content = "1.案件管辖问题{【标签1】默认内容1}测试测试测试测试测{【标签2】默认内容2}试测试测试测试测试测试测试测试测试测试测试";
        String pattern = "\\{(【.*?】)([^,,].*?)\\}";

        Pattern p = Pattern.compile(pattern);
        Matcher matcher = p.matcher(content);

        while (matcher.find()) {
            String group = matcher.group();
            int start = matcher.start();
            int end = matcher.end();
            System.out.println(group + "," + start + "," + end + "\n===\n");
        }

        String content1 = "{【标签】默认内容}";
        String pattern1 = "\\{【([\\s\\S]*)】([\\s\\S]*)\\}";
        Pattern p1 = Pattern.compile(pattern1);
        Matcher matcher1 = p1.matcher(content1);
        while (matcher1.find()) {
            int  matchCount = matcher1.groupCount();
            while (matchCount >= 0) {
                String group = matcher1.group(matchCount);
                int start1 = matcher1.start(matchCount);
                int end1 = matcher1.end(matchCount);
                System.out.println(group + "," + start1 + "," + end1);
                matchCount--;
            }
        }

 

posted @ 2018-06-05 12:04  GordonDicaprio  阅读(147)  评论(0编辑  收藏  举报