From: Peter Versteegen Date: 2007-01-17T08:03:48+09:00 Subject: Re: External to internal conversion Thanks Wilson, That did it for me. I know not to mix integers and floats; that was a typing error. I know very little about regular expressions. Could you put in words what you did? Thanks again. Wilson Bilkovich wrote: > On 1/16/07, Peter Versteegen wrote: >> Wilson, >> >> I was looking more for an output like [[25.0, 26], [30, 31]], an aray >> of two arrays. >> >> Thanks, >> > > Probably easiest to do it in two steps, since bracket-matching is a > real chore in a regular expression. > >>> input = "[25.0, 26], [30, 31]" > => "[25.0, 26], [30, 31]" >>> groups = input.scan(/\[.*?\]/) > => ["[25.0, 26]", "[30, 31]"] >>> output = groups.map {|g| g.scan(/\d+\.?\d*/).map {|n| n.to_i} } > => [[25, 26], [30, 31]] > > Do you really need 25.0 instead of 25? Mixing integers and floats can > be a bad idea. Adjust the 'to_i' call accordingly. -- Posted via http://www.ruby-forum.com/.