From: "Rebhan, Gilbert" Date: 2007-02-23T19:20:52+09:00 Subject: Re: File.open with line =~ /.../ Hi, -----Original Message----- From: Carlos [mailto:angus@quovadis.com.ar] Sent: Friday, February 23, 2007 10:46 AM To: ruby-talk ML Subject: Re: File.open with line =~ /.../ > i tried with > > File.open("Y:/test/sample.txt", "r").each do |line| > puts $1<<' : '<< $3 if line =~ /(\w+)\s+(\w+=)(\w+)/ > end > > but somehow the regex doesn't work ?! > whereas it works in the QuickRex Plugin for Eclipse /* Well... for each line of the file you are trying to match 2 lines. That's impossible :). Read the file in "paragraph mode" and match each paragraph, or read it whole and scan it for your regexp. * Strike, ouch ;-) yup line != lines /* For example (not tested): File.read('...').scan(/^(\w+)\s*\n\w+=(\w+)$/) {|a,b| puts a+": "+b} */ works like a charm. Thanks !! Regards, Gilbert