Expression regulière: Trouver le nombre de groupe d’un match

Author:

 date, java
{filelink=6449}

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GroupeNbr
 {

  public static void main(String args[])
  {
  	// Matcher la syntaxe d'une heure
    Pattern date_patern = Pattern.compile("(([0-2]?[0-9]):([0-5][0-9]))");

    String my_date = "02:59"; // Heure à vérifier
    Matcher matcher = date_patern.matcher(my_date);

     if(matcher.matches())
     {
     	System.out.println (matcher.groupCount());  // "3"
     }

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *