+ 5

Can anyone tell me why test case-8 fails ???

def is_valid(str) str =~ /(?=.*[A-Za-z\d@$!#%*?&])(?=.*[A-Za-z])(?=.*\d)(?=.*[A-Za-z\d@$!%*#?&])[A-Za-z\d@$!#%*?&]{5,16}$/ end password = gets # Hello@$World19 if password.length >= 7 and is_valid(password) puts "Strong" else puts "Weak" end

8th Aug 2020, 6:06 AM
VIGNESH MARADIYA
VIGNESH MARADIYA - avatar
4 ответов
8th Aug 2020, 6:37 AM
777
777 - avatar
+ 1
I'm not an expert in Ruby, but I know a bit of Regex. You can test each of the criteria "separately", rather than using that loooooong exp as, - 2 nums: /\d.*?\d/ \d matches a digit .*? matches as few char as possible (lazy, could match none) \d matches another digit - 2 of special char: /[!@#$%&*].*?[!@#$%&*]/ the same meaning That's it!
8th Aug 2020, 6:22 AM
777
777 - avatar
0
@RahulVerma Can you explain me by writting in code???
8th Aug 2020, 6:23 AM
VIGNESH MARADIYA
VIGNESH MARADIYA - avatar
0
@RahulVerma Thanks bro
8th Aug 2020, 6:39 AM
VIGNESH MARADIYA
VIGNESH MARADIYA - avatar