Right way to extract multiple values from string using regex in ruby 1.8
===

I'm relatively new to ruby and I'm trying to figure out the "ruby" way of extracting multiple values from a string, based on grouping in regexes. I'm using ruby 1.8 (so I don't think I have named captures).

I could just match and then assign $1,$2 - but I feel like there's got to be a more elegant way (this is ruby, after all).

I've also got something working with grep, but it seems hackish since I'm using an array and just grabbing the first element:



    input="FOO: 1 BAR: 2"
    foo, bar = input.grep(/FOO: (\d+) BAR: (\d+)/){[$1,$2]}[0]
    p foo
    p bar

I've tried searching online and browsing the [ruby docs][1], but haven't been able to figure anything better out.

  [1]: http://ruby-doc.org/core-1.8.7/Enumerable.html