From: Paolo Negri Date: 2007-07-11T08:05:33+09:00 Subject: Re: Help: Efficient regular expression sorry for being OT since I'm not going to talk about ruby or regexp If the string you're parsing is an output from the ps command you can simplify your life using the -o option that prints only the fields you need. I.E. in gnu Linux ps -ao pid,command just outputs pid and command columns. Be careful since the command column can contain spaces. Paolo On 10/07/07, Divya Badrinath wrote: > string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash" > > i need to fetch 14051 and /bin/bash from the string > > can someone help me to write an efficient regular expression for that. > > i am a beginner, i wrote > string =~ /(\d+)\s+(\d+)\s+\d+\s+\d+:\d+\s+.*\s+\d+:\d+:\d+\s+(.*)\s/ > > i know this is not the efficient way of doing it. > > Please help. > > -- > Posted via http://www.ruby-forum.com/. > >