[Solved] How to matche all the words from a string that starts and ends with double underscore in rails [closed] September 20, 2022 by Kirat As @aspend mentioned above you will get result just by using .flatten property of array class: <% str = "Hello my name is __john__ and i am __30__ years old"%> <%=str.scan(/__(.*?)__/).flatten %> Preview: 2 solved How to matche all the words from a string that starts and ends with double underscore in rails [closed]