+ 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
4 Antworten
+ 2
Here is your improved code,
https://code.sololearn.com/c6JjbxqonRpT/?ref=app
+ 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!
0
@RahulVerma Can you explain me by writting in code???
0
@RahulVerma Thanks bro