Raj Shakya Raj Shakya - 2 months ago 7
Ruby Question

how to match words in a string using regex

I have a string like this

test = "row-even row-dd testing"


Now i want to only get words that starts with
row-
.

I used test =~ /row-(.*)/
but it kept returning me 0.anyidea how i can do this?

Answer

0 is the starting position of the pattern found.

Try this instead:

puts test.scan(/row-\w+/)