Joel VanderWerf
10/22/2006 1:55:00 AM
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