Can someone tell me why this method is always returning true, even when the string does not match the pattern? I’ve ran the regex through TextWrangler’s regex engine, and the pattern is correct. Thanks
def validatePEM pem
if /^-{4}([-\s])BEGIN/.match(pem)
print "validatePEM found a match\n"
return true
else
return false
end
end
@s = '---BEGIN RSA PRIVATE KEY-----'
if validatePEM @s
print "VALID PEM FILE\n"
else
print "INVALID PEM FILE\n"
end
Just as a FYI, there are several things done in “un-Ruby” ways.
I’d write:
something like:
The use of a ternary statement for printing is something that some might question when writing in Ruby, but the Ruby Style guide agrees that writing trivial conditional tests with ternary (
?:) is OK.