Wait, you are parsing HTML with regex? I need to post this, then: http://www.codinghorror.com/blog/archives/001311.html :) On Jan 4, 2010, at 5:50 AM, W. James wrote: > Ayumu Aizawa wrote: > >> regex = /href="http:\/\/(.*?)\/.*" target="_blank"/ >> >> File.open("index.html") do |f| >> f.each_line do |c| >> puts $1 if c =~ regex >> end >> end > > regex = /href="http:\/\/(.*?)\/.*" target="_blank"/ > IO.foreach("index.html"){|line| puts $1 if line =~ regex } > > > > With no looping: > > regex = /href="http:\/\/(.*?)\/.*" target="_blank"/ > puts IO.readlines("index.html").map{|s| s[ regex, 1 ] }.compact > > -- > >