In article <20020518030951.GI9684 / panoptic.com>, Dossy <dossy / panoptic.com> wrote: > Maybe this is Perl envy, maybe I'm just doing something wrong. > I'd like to be able to say this: > > x, y = "foo bar" =~ /(foo) (bar)/ > > and x == "foo" and y == "bar" > > Currently, String#=~ returns the character of the first match. > I have to do this: > > "foo bar" =~ /(foo) (bar)/ > junk, x, y = $~.to_a > or > x, y = $1, $2 > > More Perl wantsarray() envy, too. ;-) Well, if you want a somewhat involved one-line approach... /(foo) (bar)/.match("foo bar")[1..-1] I tried: class String def =~(re) re.match(self)[1..-1] end end But it seems Ruby doesn't like overloading the =~ operator.