码迷,mamicode.com
首页 > 编程语言 > 详细

java正则 以什么开始,以什么结束

时间:2017-07-30 17:05:33      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:pattern   private   结束   solution   color   html   res   正则   string   

public class RegTest {

    public static void main(String[] args){
        String regex = "\\[([\\s\\S]*?)\\[";
        String str = "[begin]111[end] [begin]222[end] [begin]333[end] ";
        getQuestionResolution(regex, str);

        System.out.println("------------------------");

        String regex2 = "\\[([\\s\\S]*)\\[";
        getQuestionResolution(regex2, str);

    }
    private static void getQuestionResolution(String regex,String html){

        Matcher matcher = Pattern.compile(regex).matcher(html);
        while (matcher.find()){
            //group是针对()来说的,group(0)就是指的整个串,group(1) 指的是第一个括号里的东西,group(2)指的第二个括号里的东西。
       //
group()= group(0)

System.out.println(matcher.group().trim());
        }
    }
}

 

java正则 以什么开始,以什么结束

标签:pattern   private   结束   solution   color   html   res   正则   string   

原文地址:http://www.cnblogs.com/oskyhg/p/7259324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!