From: Robert Klemme Date: 2004-08-17T03:31:00+09:00 Subject: Re: Rubish Way of extracting elements "Florian Gross" schrieb im Newsbeitrag news:2oc3f4F88pl1U1@uni-berlin.de... > Daniel V�lkerts wrote: > > > <165> Aug 16 17:01:35 localhost Just a test > > I was trying to reach this form > > > > var = content > > > > pri = 165 > > timestamp = Aug 16 17:01:35 > > device = localhost > > msg = Just a test > > This ought to work, but there might be other ways to do this: > > if md = /^<(\d+)> (\S+ \d+ \d+:\d+:\d+) (\S+) (.*?)$/.match(text) > pri, timestamp, device, msg = *md.captures > # Do something with the captures > end Some more admittedly ugly constructions: val = "<165> Aug 16 17:01:35 localhost Just a test" unless ( ( pri, timestamp, device, msg = * /^<(\d+)> \s+ (\S+ \s+ \d+ \s+ \d+:\d+:\d+) \s+ (\S+) \s+ (.*)$/x.match(val).to_a ).empty? ) puts "matched" end pri, timestamp, device, msg = * /^<(\d+)> \s+ (\S+ \s+ \d+ \s+ \d+:\d+:\d+) \s+ (\S+) \s+ (.*)$/x.match(val).to_a if pri puts "matched" end LOG_RX = /^<(\d+)> \s+ (\S+ \s+ \d+ \s+ \d+:\d+:\d+) \s+ (\S+) \s+ (.*)$/x unless ( ( pri, timestamp, device, msg = * LOG_RX.match(val).to_a ).empty? ) puts "matched" end if ( line, pri, timestamp, device, msg = * /^<(\d+)> \s+ (\S+ \s+ \d+ \s+ \d+:\d+:\d+) \s+ (\S+) \s+ (.*)$/x.match(val) ) && line puts "matched" end if ( line, pri, timestamp, device, msg = * LOG_RX.match(val) ) && line puts "matched" end :-) robert