Return first line of parsing

mysite.each {|line|
if line =~ /

(.+)</b>/
puts “#{$2} found at: #{$1}”
end
}

Ok guys, Lets say the website has 50+ lines… and i only want to return
the first one, any ideas?

On 8/17/07, Haze N. [email protected] wrote:

mysite.each {|line|
if line =~ /

(.+)</b>/
puts “#{$2} found at: #{$1}”
end
}

Ok guys, Lets say the website has 50+ lines… and i only want to return
the first one, any ideas?

%r/^(.*)$/.match(mysite)[1]

On Aug 17, 2007, at 8:59 AM, Tim P. wrote:

%r/^(.*)$/.match(mysite)[1]

Careful,
What if the site’s white space has been stripped? (no CR or LF at all)
or if the html/xhtml is screwy? (old html without closed elements,
or just poorly formed or badly nested)

On Friday 17 August 2007 02:59:39 pm John J. wrote:

Ok guys, Lets say the website has 50+ lines… and i only want to
return
the first one, any ideas?

%r/^(.*)$/.match(mysite)[1]

Careful,
What if the site’s white space has been stripped? (no CR or LF at all)
or if the html/xhtml is screwy? (old html without closed elements,
or just poorly formed or badly nested)

The first line of any file doesn’t depend on the html in it. His code
should return the first line of any file – html or no.

On Aug 17, 8:52 am, Haze N. [email protected] wrote:

Posted viahttp://www.ruby-forum.com/.
If you want to use essentially the same block as above, but just take
the first matching line:

mysite.each {|line|
if line =~ /

(.+)</b>/
puts “#{$2} found at: #{$1}”
break
end
}

Tim’s solution would give you the first line of the actual html file
and, as John mentions, that could be the entire web page if there are
no CR/LF characters in the file.

Jeremy