[Ruby] what does second instruction do? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Resposta
+ 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