# Re: getting the next line with the iterator

**URL:** <https://www.ruby-forum.com/t/re-getting-the-next-line-with-the-iterator/94304>\
**Category:** Ruby\
**Created:** [April 28, 2006, 9:48am UTC](https://www.ruby-forum.com/t/re-getting-the-next-line-with-the-iterator/94304 "2006-04-28T09:48:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [April 28, 2006, 9:48am UTC](https://www.ruby-forum.com/t/re-getting-the-next-line-with-the-iterator/94304/1 "2006-04-28T09:48:05Z")

</div>

> while g.next?  
> if g.next =~ /regExp/  
> 3.times { list \<\< g.next }  
> end  
> end  
> end  
> puts list

Well, yes. In the general case I would agree.  
In this case I think

list = []  
File.open(‘toto.txt’, ‘rb’) do |myFile|  
while line = myFile.gets do  
3.times {list \<\< myFile.gets} if line =~ /regExp/  
end  
end  
puts list

is totally sufficient.

cheers

Simon
