[Codecoach]What would be the regex for this ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[Codecoach]What would be the regex for this ?

my string should satisfy : 1. two special char(#$@!&*) 2. minimum two digits 3. minimum length :7 I tried with This: "^((?=.*[#$@!*&%]{2,})(?=.*[a-zA-Z]{0,})(?=.*[0-9]{2,})).{7,}

quot; Edit: 1. This is actually for Codecoach problem password validation. last test case is still not passing. Why ? 2. "^(?=.*\W{2,})(?=.*\d{2,}).{7,}
quot; This is shorter version of my regex. Even this fails for the last test case. Why ? 3. "(?=(.*[0-9]){2,})(?=(.*[!@#$%&*]){2})(?=.{7,})" This passes all the test cases ! Why?

3rd Jun 2020, 8:22 AM
Hima
Hima - avatar
5 Answers
+ 2
"(.*[#$@!&*]{1}[A-Za-z]{0,} \d{2})"
3rd Jun 2020, 8:35 AM
Still Codes
Still Codes - avatar
0
Haven't tried though
3rd Jun 2020, 8:41 AM
Still Codes
Still Codes - avatar
0
Just check for string length and if it is equal or greater than 8, if so, then move to check for the other requirements.
3rd Jun 2020, 8:53 AM
Jay W
0
Jay W with regex ?
3rd Jun 2020, 8:54 AM
Hima
Hima - avatar
0
Well, with regex you can do {8,}
3rd Jun 2020, 8:57 AM
Jay W