Assignment finished - Completed Main and Bonus exercises #1
@@ -62,8 +62,18 @@ public class BonusExercises {
|
||||
- has no white-space in it
|
||||
*/
|
||||
public int findValidPasswords(String string) {
|
||||
// todo
|
||||
return -1;
|
||||
String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
String[] parts = string.split("\\s+");
|
||||
int counter = 0;
|
||||
for(String part : parts){
|
||||
Matcher matcher = pattern.matcher(part);
|
||||
if(matcher.matches()){
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user