This is a simple code to parse a simple string in ruby
str = "Amdh#34HB!x"
length = str.length
upper = str.scan(/[A-Z]/).count #count upper chars
lower = str.scan(/[a-z]/).count #count lower chars
digit = str.scan(/[0-9]/).count #count digits
special = str.scan(/[^a-z0-9]/i).count #count special chars
result = "Length : " + length.to_s + " Upper : " + upper.to_s + " Lower : " + lower.to_s + " Digit : " + digit .to_s + " Special : " + special.to_s
The result is given as "Length : 11 Upper : 3 Lower : 4 Digit : 2 Special : 2"
I want to do the same things to an array of strings
array = ["Amdh#34HB!x", "AzErtY45", "#1A3bhk2"]
and so I can know the details like above of each element of the array
Example :
array[0] = "Length : 11 Upper : 3 Lower : 4 Digit : 2 Special : 2"
array[1] = "Length : 8 Upper : 3 Lower : 3 Digit : 2 Special : 0"
array[2] = "Length : 8 Upper : 1 Lower : 3 Digit : 3 Special : 1"
....
I know the answer seems simple by using each method but didn't find the right way to do it.
The code above is not optimised, if there is any better suggestion, you are welcome!