+ 2
[Ruby] what does second instruction do?
l = 'abcde' puts l =~/ab?/
1 Respuesta
+ 7
Paolo De Nictolis
I found this in www.rubyguides.com
Matching Operator (=~)
What is this funny-looking Ruby operator (=~) with a tilde?
It’s the matching operator!
It allows you to do a quick index search using a regular expression.
Playing with your code, I can see that it returns the index of the first letter of the regular expression
The ? mark indicates that the letter following the first letter can be anything, not part of the search.
I am assuming the / before and after the string , creates the regular expression