# Extracting range of lines

**URL:** <https://www.ruby-forum.com/t/extracting-range-of-lines/143119>\
**Category:** Ruby\
**Created:** [July 15, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/extracting-range-of-lines/143119 "2008-07-15T13:12:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmarc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/4491bb/32.png) [@tmarc](https://www.ruby-forum.com/u/tmarc)\
**Post date:** [July 15, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/extracting-range-of-lines/143119/1 "2008-07-15T13:12:39Z")

</div>

Hello,

are there a ruby equivalents to perl’s /regex/ … /regex/ and /  
regex/ … /regex/ idioms, examples described at  
[http://www.unix.com.ua/orelly/perl/cookbook/ch06\_09.htm](http://www.unix.com.ua/orelly/perl/cookbook/ch06_09.htm)?

I’ve been googling around with no relevant results.

Thanks in advance,  
Tom

---

<div class="post-metadata">

**Author:** ![tmarc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/4491bb/32.png) [@tmarc](https://www.ruby-forum.com/u/tmarc)\
**Post date:** [July 15, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/extracting-range-of-lines/143119/2 "2008-07-15T13:47:10Z")

</div>

the link is not working (i would need to sign up to the forum  
first…)

---

<div class="post-metadata">

**Author:** ![tmarc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/4491bb/32.png) [@tmarc](https://www.ruby-forum.com/u/tmarc)\
**Post date:** [July 15, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/extracting-range-of-lines/143119/3 "2008-07-15T14:00:03Z")

</div>

From: tmarc [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# are there a ruby equivalents to perl’s /regex/ … /regex/ and /

# regex/ … /regex/ idioms, examples described at

# [Recipe 6.8. Extracting a Range of Lines](http://www.unix.com.ua/orelly/perl/cookbook/ch06_09.htm)?

# I’ve been googling around with no relevant results.

try searching for ruby+range+flip+flop

iianm, _that_ perl/sed style is being deprecated.

eg,

File.open(“test.txt”) do |f|  
while line=f.gets  
p line  
end  
end  
“–first\n”  
“1234\n”  
“456\n”  
“4321\n”  
“654\n”  
“–second\n”  
“546\n”  
“3456\n”  
“5436\n”  
“9879\n”  
“–third\n”  
“1111\n”  
#=\> nil

File.open(“test.txt”) do |f|  
while line=f.gets  
p line if line =~ /^–second/ … /^–third/  
end  
end  
“–second\n”  
#=\> nil

so you get weird results.

the new ruby syntax is like,

File.open(“test.txt”) do |f|  
while line=f.gets  
p line if line =~ /^–second/ … line =~ /^–third/  
end  
end  
“–second\n”  
“546\n”  
“3456\n”  
“5436\n”  
“9879\n”  
“–third\n”  
#=\> nil

hth.  
kind regards -botp
