Raj Shakya Raj Shakya - 1 year ago 82
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?

Answer Source

0 is the starting position of the pattern found.

Try this instead:

puts test.scan(/row-\w+/)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download