From: "Joec_49@..." Date: 2011-10-04T01:42:31+09:00 Subject: Re: Need some help with regexp $~ has the matched result from the most recent regexp. Convert to a string thusly ($~).to_s Joe Sent from my iPad On Oct 3, 2011, at 6:00 AM, Robert Klemme wrote: > 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/ > >