测试正则表达式的分组

import java.util.regex.*;

public class RegGroup{

    public static void main(String[] args){
        
        Pattern p = Pattern.compile("([a-z]{2,4})(\\d+)");
        Matcher m = p.matcher("sdf1234-fasd345-fd46");
        while(m.find()){
            System.out.println(m.group());
            //System.out.println(m.group(1));
            //System.out.println(m.group(2));
        }        
    }
}

 

posted @ 2020-04-02 12:32  yxfyg  阅读(348)  评论(0)    收藏  举报