+ 5
Ruby - What does this code do?
l = 'abcde' puts l =~ /ab?/
2 Answers
+ 3
It looks for the pattern "a" or "ab" and returns the index where it begins in the string.
(puts l =~ /e/) returns 4
a b c d e
0 1 2 3 4
+ 2
is comparing l with regex isnt it?
ab? means ab occurence is 0 or more