From: Paul Date: 2010-10-09T06:10:22+09:00 Subject: Re: How can I count number of elements in an HTML page On Oct 5, 9:33 pm, Steel Steel wrote: > > I can find the section I want with a regex but I don't know how to > > iterate through the string looking for particular elements.  I was > > thinking about taking the section I'm interested in and saving it as > > an array and then iterating through each array element (html line) > > that way, but I thought there might be a quicker way to do it. > > $html.scan(%r{}m).to_s.scan(/
  • /).size Thanks Steel. This worked fine. I just needed to make it a lazy search with .*? I've got nothing against Nokogiri or the other solutions but I was hoping for a solution like this that just uses the core libraries for portability. Cheers! Paul.