# Printing

**URL:** <https://www.ruby-forum.com/t/printing/122702>\
**Category:** Ruby\
**Created:** [December 11, 2007, 12:42am UTC](https://www.ruby-forum.com/t/printing/122702 "2007-12-11T00:42:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [December 11, 2007, 12:42am UTC](https://www.ruby-forum.com/t/printing/122702/1 "2007-12-11T00:42:59Z")

</div>

hi

im trying to:

# open a .txt file and read all the lines in the file

# run a regular expression to find in the form of (some text) (then

anything in [])(some text)

# iterate through each line in the file until no references left

i have achieved the following but i want to print out the references

im unsure how to do this.  
any help would be much appreciated  
iv provided my code below

thanks

ruby class:

File.open(‘testnew.txt’).each do |line|  
if line =~ /(._?)[(._?)](.\*)/  
end

puts

.txt file - i know it doesnt make any sense

uhvbguyfgtyftyf [ref1] jhvbufgytf [ref2, ref1]  
jhvytfdr [ref2]

---

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [December 12, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/printing/122702/2 "2007-12-12T20:35:16Z")

</div>

On Dec 10, 4:42 pm, Johnathan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> iv provided my code below
> 
> ruby class:
> 
> File.open(‘testnew.txt’).each do |line|  
> if line =~ /(._?)[(._?)](.\*)/  
> end

File.open(‘testnew.txt’).each do |line|  
if line =~ /(._?)[(._?)](.\*)/  
puts line  
end  
end
