Colin Summers
6/15/2007 6:02:00 AM
I have a page of html, the usual thing. It has an ordered list. So it has
<ol>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ol>
Well, I am going through this my usual way, which is just brute force
string manipulation. It's still my first day with Ruby. Then I see
str.scan
Both forms iterate through str, matching the pattern (which may be a
Regexp or a String). For each match, a result is generated and either
added to the result array or passed to the block. If the pattern
contains no groups, each individual result consists of the matched
string, $&. If the pattern contains groups, each individual result is
itself an array containing one entry per group.
And I think, oooh, I bet that would be cool to use here. But my regexp
is rusty and I'm not sure how I would set it up
items = page.scan('<li>*</li>')
something like that? Then items would be an array of the text in the items?
Looked cool, anyway. I love how terse it can be.
There's probably also an html/xml parsing library, but I don't have
THAT much of this stuff to do, so I think a little manual work is
probably simpler/easier to learn.
--Colin