views:

93

answers:

5

http://services.tvrage.com/tools/quickinfo.php?show=Chuck

I'm trying to parse that info, for exmaple, get the Airtime,

Airtime@Monday at 08:00 pm

I want to get what's after "Airtime@" till the end of the line, to just come out with "Monday at 08:00 pm". How can I do this?

A: 

Why regex? Any problem getting substring?

s = "Airtime@Monday at 08:00 pm"
puts s[8..-1] # => Monday at 08:00 pm

edit
ok, this is for other options

puts s[s.index('@') + 1..-1]
Nikita Rybak
Because there are other options aswell, such as "Show ID", ect.
Rickmasta
A: 
result = allyourtextdata[/Airtime@(.+)/,1]

Or if you are also going to use some another strings from this report:

hash = Hash[allyourtextdata.scan(/(.+?)@(.+)/)]
p hash["Airtime"] # this will print "Monday at 08:00 pm"
Nakilon
Not exactly what I wanted, but it lead me the way! Thanks man!
Rickmasta
+2  A: 

Is there any reason you don't use the XML feeds?

require 'open-uri'
require 'nokogiri'

d = Nokogiri.XML(open 'http://services.tvrage.com/feeds/showinfo.php?sid=15614')

name = d.search('//showname').text               # => 'Chuck'
day  = d.search('//airday').text                 # => 'Monday'
time = d.search('//airtime').text                # => '20:00'
net  = d.search('//network[@country="US"]').text # => 'NBC'

puts "#{name} airs #{day}s at #{time} on #{net}."
# Chuck airs Mondays at 20:00 on NBC.
Jörg W Mittag
A: 
require 'net/http'
url=URI.parse('http://services.tvrage.com/tools/quickinfo.php?show=Chuck')
response = Net::HTTP.get_response(url)
data=response.body
puts data.scan(/.*Airtime@(.*)\n/)
A: 

This is a great site for testing ruby regex expressions: http://rubular.com/

Daniel