[Ruby] what does second instruction do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

[Ruby] what does second instruction do?

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

1st Dec 2021, 6:41 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 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
1st Dec 2021, 9:30 PM
Rik Wittkopp
Rik Wittkopp - avatar