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.
j'en air créé une comme ça:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2String chaine = "toto 1234";
Et voisi le résultat:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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"); }
je pensais de n'avoir que 2 groupes, mais apparemment j'en ai 3; Est-ce normal?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 roup : iofv 154 group : iofv group : 154
Partager