From: "trans. (T. Onoma)" Date: 2004-10-22T10:38:24+09:00 Subject: A little help on finding the closest match Better way to find the closest match? # example data str = "some string abc xyz" tokens = [ /abc/, /xyz/ ] i = 0 # must be a better way? token,match,mindex = tokens.inject([nil,nil,str.length]){ |memo, tkn| s = str.index( tkn.start_pattern, i ) if s s < memo[2] ? [tkn, $~, s] : memo else memo end } In this case this should return a match to 'abc' (this case has not been tested, but the core of this example has) Thanks, T.