+ 5

Ruby - What does this code do?

l = 'abcde' puts l =~ /ab?/

26th Apr 2019, 4:46 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
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
26th Apr 2019, 5:24 PM
Diego
Diego - avatar
+ 2
is comparing l with regex isnt it? ab? means ab occurence is 0 or more
26th Apr 2019, 4:54 PM
Taste
Taste - avatar