From: Ken Collins Date: 2006-10-04T21:34:06+09:00 Subject: Re: Using a Regexp to find a Hash Key? I sure could... The hash is going to be real small. It would at most only have 3 or 4 keys. The one I want has a prefix of an arbitrary string with any amount of number after it. I need to know if this key is present so that I can run a conditional block of code. It would be a bonus to get some match data back on that last series of digits in the regexp. I would like to use something like this: def foobar if hash.has_key?(/^foo_\d+$/) ... end end Meanwhile my code looks like this and I was pretty sure there might be a more terse solution. def foobar unless params.reject{ |k, v| k !~ /^foo_\d+$/ }.empty? ... end end On Oct 4, 2006, at 12:20 AM, Paul Lutus wrote: > Ken Collins wrote: > >> > > This is possible, but it is rather cumbersome and slow, since the > regexp has > to be applied to each hash key in turn until a match is found. > > Maybe you could provide more detail about the problem to be solved > instead > of this notion about how to solve it. Even one word more. > > -- > Paul Lutus > http://www.arachnoid.com >