From: tamouse mailing lists Date: 2013-04-17T11:43:54+09:00 Subject: Re: How to get the only the partial of text Looking at OP's sample output, they want it without the trailing :ddd (port?), so: /-(.*?):/ will give just the second ip. N.B.: scan returns each match group as a single element array inside the array of matches. So doing something like: input.map {|line| line.scan /-(.*?):/ } gives: [[["192.168.1.22"]], [["192.168.1.21"]]] which might be a lot to unpack. #flatten will fix that up: input.map {|line| line.scan /-(.*?):/ }.flatten # => ["192.168.1.22", "192.168.1.21"] On Tue, Apr 16, 2013 at 5:28 PM, Joel Pearson wrote: > Oops, I missed the final part. This one should do it: > > my_string.scan /-([^ ]+)/ > > http://www.rubular.com/r/hUH1c4amH1 > > -- > Posted via http://www.ruby-forum.com/. >