7stud2
(7stud --)
1
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
···
--
Posted via http://www.ruby-forum.com/.
7stud2
(7stud --)
2
How about this?
my_string.scan /-(.+)(?=:)/
http://www.rubular.com/r/vFIr2py40i
···
--
Posted via http://www.ruby-forum.com/.
7stud2
(7stud --)
3
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/.
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 <lists@ruby-forum.com> 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/.