From: 7stud -- Date: 2012-12-20T08:55:08+09:00 Subject: Re: Perl to Ruby: regex captures to assignment. frac_str = "1 3/4" w, n, d = frac_str.match(/\//) \ ? frac_str.match(/(?:(\S+) )*?(\S+)\/(\S+)/).captures \ : [0, frac_str, 1] puts "w: #{w}, n: #{n}, d: #{d}" # check assignment --output:-- w: 1, n: 3, d: 4 frac_str = "1 3/4" md = frac_str.match %r{(\d+ )?(\d+)/(\d+)} w, n, d = md ? md.captures : [frac_str.to_i, 0, 1] puts "w: #{w}, n: #{n}, d: #{d}" # check assignment --output:-- w: 1 , n: 3, d: 4 -- Posted via http://www.ruby-forum.com/.