测试正则表达式的分组

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));
        }        
    }
}

猜你喜欢

转载自www.cnblogs.com/yxfyg/p/12618889.html