From: Mike Harris Date: 2007-01-13T04:29:18+09:00 Subject: Re: DRY gsub... Josselin wrote: > I wrote the following ruby statements.. I get the result I need , I > tried to DRY it for 2 hours without being successfull , > > d = d.gsub(/\r\n/,' ') # get rid of carriage return > d = d.gsub(/;/,' ') # replace column by space > d = d.gsub(/,/,' ') # replace comma by space > a = d.split(' ') # split into component , space as divider > > tfyl > > Joss > > > Specific to this example, everyone else is right, and the best way is to consolidate the regex or simply use a condensed split call. However, in the general case, you could do this [ /\r\n/ , /;/ , /,/].inject(d) { |s,reg| s.gsub(reg,' ') }.split(' ')