From: Joel VanderWerf Date: 2006-10-22T10:55:29+09:00 Subject: Re: DRY fanatics? Giles Bowkett wrote: > Anybody know a way to make this DRYer? > > when /^([A-Za-z0-9,]+), '([^']+)', '([^']+)', '([^']+)'/ > > a literal regex with a subpattern repeated three times > > I could probably split on the ', but it seems that might have unwanted > side effects. This doesn't help much, unless the 3 comes from a variable, but ... case "a, 'b', 'c', 'd'" when /^([A-Za-z0-9,]+)((?:, '[^']+'){3,3})/ p $1, $2.scan(/'([^']+)'/) # when /^([A-Za-z0-9,]+), '([^']+)', '([^']+)', '([^']+)'/ # p $1, $2, $3, $4 end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407