Assignment finished - Completed Main and Bonus exercises #1
@@ -62,8 +62,18 @@ public class BonusExercises {
|
|||||||
- has no white-space in it
|
- has no white-space in it
|
||||||
*/
|
*/
|
||||||
public int findValidPasswords(String string) {
|
public int findValidPasswords(String string) {
|
||||||
// todo
|
String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$";
|
||||||
return -1;
|
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