Return first line of parsing

mysite.each {|line|
  if line =~ /<p><a href="(.+)"><b>(.+)<\/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?

···

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

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

···

On 8/17/07, Haze Noc <h4z3@the-c0re.org> wrote:

mysite.each {|line|
  if line =~ /<p><a href="(.+)"><b>(.+)<\/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?

If you want to use essentially the same block as above, but just take
the first matching line:

mysite.each {|line|
  if line =~ /<p><a href="(.+)"><b>(.+)<\/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

···

On Aug 17, 8:52 am, Haze Noc <h...@the-c0re.org> wrote:

mysite.each {|line|
  if line =~ /<p><a href="(.+)"><b>(.+)<\/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?
--
Posted viahttp://www.ruby-forum.com/.

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 Aug 17, 2007, at 8:59 AM, Tim Pease wrote:

On 8/17/07, Haze Noc <h4z3@the-c0re.org> wrote:

mysite.each {|line|
  if line =~ /<p><a href="(.+)"><b>(.+)<\/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]

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 Friday 17 August 2007 02:59:39 pm John Joyce wrote:

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

> On 8/17/07, Haze Noc <h4z3@the-c0re.org> wrote:
>> mysite.each {|line|
>> if line =~ /<p><a href="(.+)"><b>(.+)<\/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]
>
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)

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/