From: Robert Klemme Date: 2009-12-18T23:39:40+09:00 Subject: Re: grep a block 2009/12/18 beny 18241 : > ok closed Ifigue it out :) > > puts ARGF.read.scan(/.*?<\/mms:MmsCcppAccept>/m) Eric's solution is better for large files because it requires reading the file line by line only. Note that it uses a special feature of "if" when using a range with boolean expressions: in that case matching state is stored and the complete expression is true when the first matches, stays true and only switches back to false if the second matches: irb(main):001:0> 10.times {|i| if /^3/ =~ i.to_s .. /^7/ =~ i.to_s; puts i; end} 3 4 5 6 7 => 10 irb(main):002:0> 10.times {|i| if i == 3 .. i == 7; puts i; end} 3 4 5 6 7 => 10 Note: the second example is merely for demonstration purposes, it can also be done with a single integer range match: irb(main):003:0> 10.times {|i| if (3..7) === i; puts i; end} 3 4 5 6 7 => 10 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/