hi
bellow is a text . but i just need the 2nd half of the ip till :110
ip=192.168.1.22-192.168.1.22:110 adm_status=0 holddown_interval=300
max_connections=0 weight=1 option=01
alive=0 total=1 enable=00000001 alive=00000000 power=0
ip=192.168.1.21-192.168.1.21:990 adm_status=0 holddown_interval=300
max_connections=0 weight=1 option=01
alive=0 total=1 enable=00000001 alive=00000000 power=0
So basically , i just want :192.168.1.22:110 , 192.168.1.21:990
But dont understand how to get that
thanks for the help and showing me some good path to further study
Thanks
How about this?
my_string.scan /-(.+)(?=:)/
http://www.rubular.com/r/vFIr2py40i
Oops, I missed the final part. This one should do it:
my_string.scan /-([^ ]+)/
http://www.rubular.com/r/hUH1c4amH1
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”]