From: "Peña, Botp" Date: 2007-07-11T13:58:01+09:00 Subject: Re: Help: Efficient regular expression From: Peña, Botp [mailto:botp@delmonte-phil.com] # On Behalf Of Divya Badrinath: # # string = "root 14051 14033 3 08:39 pts/2 00:00:00 # /bin/bash -x -s" # # it fetches only -s for me. # # sec, last = string.split.values_at(1, -1) # # doesnt work for the same reason # # i need everything after 00.00.00 till the end # # i.e., /bin/bash -x -s # # you can modify the non-regex solutions since they are just # plain array manipulations # # irb(main):003:0> str = "root 14051 14033 3 08:39 pts/2 # 00:00:00 /bin/bas # h -x -s" # => "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash -x -s" # irb(main):006:0> astr = str.split # => ["root", "14051", "14033", "3", "08:39", "pts/2", # "00:00:00", "/bin/bash", "- # x", "-s"] # irb(main):007:0> pid = astr[1] # => "14051" # irb(main):010:0> cmd = astr[7..-1].join " " # => "/bin/bash -x -s" # # or # # irb(main):024:0> pid,*cmd = astr.values_at(1,7..-1) # => ["14051", "/bin/bash", "-x", "-s"] # irb(main):025:0> pid # => "14051" # irb(main):026:0> cmd # => ["/bin/bash", "-x", "-s"] # irb(main):027:0> cmd = cmd.join " " # => "/bin/bash -x -s" i forgot to add the last one; it's niftier, so i would not want you to miss it. irb(main):060:0> pid,cmd=str.split(" ",8).values_at(1,7) => ["14051", "/bin/bash -x -s"] irb(main):061:0> pid => "14051" irb(main):062:0> cmd => "/bin/bash -x -s" i totally forgot about the second param of split. ruby is cool, indeed :) kind regards -botp