Raj Shakya Raj Shakya - 1 month ago 5x
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

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


0 is the starting position of the pattern found.

Try this instead:

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