From: Gary Watson Date: 2010-09-18T05:10:45+09:00 Subject: Re: ruby regexpresion Ruwan Budha wrote: > (21:15:32:873) SMART>> Starting Process '/abs/nc/qwcy/xyz'. pid 11560 > > > I want to parse the following few things from the above string > > (21:15:32:873) > xyz > pid 11560 > > and output as below, > > (21:15:32:873), xyz, pid 11560 > > > I am stuck and I would appreciate if someone could give me some help. I > am newbie to ruby....thanks another answer is s = "(21:15:32:873) SMART>> Starting Process '/abs/nc/qwcy/xyz'. pid 11560" s =~ /^(\(.*?\)).*'\/.*?\/.*?\/.*?\/(.*?)'.*(pid \d*)/ puts $1 puts $2 puts $3 the parentheses that capture the text are call "capturing parentheses". so the regular expression /what(.*)is(.*)this/ would sucessfully match the string "what mamamea this is crazy this" and the first captured group would be " mamamea " and the second captured group would be " crazy ". Hopefully that makes sense. -- Posted via http://www.ruby-forum.com/.