From: Robert Klemme Date: 2011-10-03T19:00:49+09:00 Subject: Re: Need some help with regexp On Mon, Oct 3, 2011 at 9:06 AM, Eyal Eizenberg wrote: > Is there a way to do it so that the $& will contain "MARCOCHEN"? > > > Isaac Sanders wrote in post #1024664: >> You are getting that because you have spaces in it. You can get the same >> result if you use /(\S+)/ and using the $1 variable, which should >> contain >> "MARCOCHEN". Even better - you don't need $&: irb(main):001:0> s="Laptop MARCOCHEN (192.168.5.73)" => "Laptop MARCOCHEN (192.168.5.73)" irb(main):002:0> s[/\A\s*\w+\s+(\w+)/, 1] => "MARCOCHEN" or irb(main):005:0> s[/\A\s*\S+\s+(\w+)/, 1] => "MARCOCHEN" Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/