Java Regex: repetitive groups?

后端 未结 3 1697
名媛妹妹
名媛妹妹 2021-01-22 05:57

How can I define repetitive groups in Java Regex?

Lets say a 2digit number [0-9]{2} multiple times separates by ,

12,34,98,11

Is that p

3条回答
  •  心在旅途
    2021-01-22 06:39

    In Java you may also use Scanner APIs for this:

    final Pattern pat = Pattern.compile("\\d{2}");
    Scanner scan = new Scanner("12,34,98,11");
    scan.useDelimiter(",");
    while(scan.hasNext(pat)) {
        System.out.println( "Token: " + scan.next() );
    }
    scan.close();
    

提交回复
热议问题