From: Caleb Clausen Date: 2009-11-13T08:24:15+09:00 Subject: Re: DRYing a Regex On 11/12/09, RichardOnRails wrote: > upper = /[A-Z]+/ > not_upper= Regexp.new( upper.source.sub( /\[/, '[^' ) ) [snip] > But the not_upper Regexp definition is really a kludge. It somewhat > camouflages what is really /[^A-Z]+/ > > I'd like to DRY it by expressing it as something like !upper. I need > something like !~ we use normally with string searches. This is somewhat better, but still not real obvious: not_upper=/(?:.(?!#{upper}))+/ #untested, tho Myself, I'd just write not_upper=/[^A-Z]/.... for something this short, is it really worth trying all that hard to be DRY?