correcte Expression Régulière
Je n'arrive pas à construire la bonne Regex pattern pour faire le check suivant:
il faut vérifier si la chaîne de caractères se termine par un ou plusieurs chiffres, par ex.
Code:
1 2
|
String chaine = "toto 1234"; |
j'en air créé une comme ça:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
String my_chaine = "iofv 154";
String my_regex = "(^\\D+)(\\d+$)";
Pattern pattern = Pattern.compile(my_regex);
Matcher matcher = pattern.matcher(my_chaine);
boolean matchFound = matcher.find();
if (matchFound) {
for (int i = 0; i <= matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println("group : " + groupStr);
}
}
else{
System.out.println("No matches");
} |
Et voisi le résultat:
Code:
1 2 3 4
|
roup : iofv 154
group : iofv
group : 154 |
je pensais de n'avoir que 2 groupes, mais apparemment j'en ai 3; Est-ce normal?