From: Dominique Plante Date: 2006-09-13T07:25:52+09:00 Subject: Re: getting the last word in each line in irb: >>r = /\w+$/ => /\w+$/ >>s = "bad boy" => "bad boy" >>md = s.match(r) => # >>md[0] => "boy" Joe Van Dyk wrote: > Is there a prettier way to read a file and return the last word in each > line? > > Here's my go: > > File.read(some_file).to_a.map { |l| line.split.last } > > What if I wanted to search the lines (based on a regex) and return the > last word in each line that satisfied the search criteria? > > Joe -- Posted via http://www.ruby-forum.com/.