7stud -- wrote:
> You can do something like this:
> 
> require 'open-uri'
> 
> url = "http://www.google.com"
> 
> open(url) do |f|
>   f.each do |line|
>     if md_obj = /<title>(.*)<\/title>/.match(line)
>       puts md_obj[1]
>     end
> 
>     if md_obj = /type=(.{6})/.match(line)
>       puts md_obj[1]
>     end
> 
>   end
> end
> 

This should be more efficient:

require 'open-uri'

url = "http://www.google.com"
title_re = Regexp.new(/<title>(.*)<\/title>/)
text_re = Regexp.new(/type=(.{5})/)

open(url) do |f|
  f.each do |line|
    if md_obj = title_re.match(line)
      puts md_obj[1]
    end

    if md_obj = text_re.match(line)
      puts md_obj[1]
      break
    end

  end
end

--output:
Google
hidde   #first 5 chars of 'hidden'

-- 
Posted via http://www.ruby-forum.com/.