java 简易正则表达式

查找

// "select SPU_ID,TITLE,CATEGORY_ID,PROPERTIES,AFFECT_PROPERTIES,pict_url,STATUS from spu_[0000-0031] [0012-2334] where status=1
        Pattern pt = Pattern.compile("\\[(\\d+-\\d+)\\]");

        Matcher match = pt.matcher(sql);
        System.out.println(sql);
        
        // 找到第一个[0000-0031]
        match.find();
        // 输出全部匹配的
        System.out.println(match.group(0));
        // 输出匹配的中第一组
        System.out.println(match.group(1));
        // 输出匹配的中第二组
        System.out.println(match.group(2));
        
        // 找到下一个[0012-2334]
        match.find();
        // 同上
        System.out.println(match.group(0));
        System.out.println(match.group(1));
        System.out.println(match.group(2));

输出:

[0000-0031]
0000
0031
[0012-2334]
0012
2334

 

posted @ 2013-03-21 15:00  mongg  阅读(260)  评论(0编辑  收藏  举报