From: Joel VanderWerf Date: 2004-01-31T07:38:31+09:00 Subject: Re: principle of most suprise Dave Lee wrote: > tony summerfelt wrote: > >>gah, ruby is doing it to me again: >> >> logline=String.new("+ 30 Jan 12:20:09 [3988] addr: x.x.x.x") >> tda=Array[(logline.split(/\[\d+\]/))] >> tda.first > > > another way of writing this code, which you may find more explicit if you > only use tda.first is to use MatchData#pre_match > > logline = "+ 30 Jan 12:20:09 [3988] addr: x.x.x.x" > marker = /\[\d+\]/ > marker.match(logline).pre_match # equivalent to tda.first from above Or using the lookahead contruct, ?=, you can do this: logline = "+ 30 Jan 12:20:09 [3988] addr: x.x.x.x" logline[/^.*(?=\[\d+\])/]