On Nov 12, 2009, at 5:00 PM, RichardOnRails wrote: > I've got a routine that works fine at building an array of upper-case > strings extracted from a string: > > aNewList = [] > s = StringScanner.new sNewList > upper = /[A-Z]+/ > not_upper= Regexp.new( upper.source.sub( /\[/, '[^' ) ) > while not s.eos? > case > when s.skip(upper); aNewList << s.matched > else s.skip(not_upper) > end > end > > 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. > > Any ideas? Well, you don't really need a StringScanner for this simple task. Your code really just rebuilds String#scan(): a_new_list = s_new_list.scan(/[A-Z]+/) Note that I've also switched your variable naming style to the snake_case that we Rubyists prefer. Hope that helps.