From: jake kaiden Date: 2011-04-08T05:57:58+09:00 Subject: Re: String.gsub with regex and block Alexey Petrushin wrote in post #991484: > > I would prefer something like: > > "John Smith".gsub /(.+)\s(.+)/ do |name, family| > p [name, family] > > # instead of this > p [$1, $2] > end i also wonder if gsub is necessary... there's no replacement here as far as i can tell. my oversimplified monkey brain comes up with this: irb(main):001:0> str = "John Smith - Minister of Funny Walks." => "John Smith - Minister of Funny Walks." irb(main):002:0> arr = str.split(" ") => ["John", "Smith", "-", "Minister", "of", "Funny", "Walks."] irb(main):003:0> name, family = arr[0], arr[1] => ["John", "Smith"] irb(main):004:0> puts name John => nil irb(main):005:0> puts family Smith => nil this also makes some assumptions about the data, of course... -j -- Posted via http://www.ruby-forum.com/.