Ruby - Regular Expressions
Consider this Ruby code snippet:
text = "abc" match = text.match(/d/) puts match[0]What is the problem here?
text = "abc" match = text.match(/d/) puts match[0]What is the problem here?
/d/ looks for 'd' in "abc", which is not present, so match returns nil.match[0] when match is nil causes a NoMethodError.match[0] when match is nil -> Option B[0] on nil causes error [OK]match is nil before accessing [OK]match can be nilmatch method is missing15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions