From: "Jesús Gabriel y Galán" Date: 2009-01-15T02:49:17+09:00 Subject: Re: Regexp in Ruby On Wed, Jan 14, 2009 at 6:41 PM, Teme Rosi wrote: > names = ["My name is Jack"] > if names =~ /My name is (\w+)/i > puts $1 > end > > > What im trying to do with this code is to print rest of the line of the > same line where "My name is" is. But it doesnt work. Can anyone help? In your snippet, names is an array, so the method =~ doesn't do anything meaningful. You need to call that on the string like this: irb(main):019:0> names = "My name is Jack" => "My name is Jack" irb(main):020:0> if names =~ /My name is (\w+)/i irb(main):021:1> puts $1 irb(main):022:1> end Jack Jesus.