From: Rick DeNatale Date: 2009-02-11T06:46:37+09:00 Subject: Re: regexp problem --00163630f0ef23c6420462977024 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Tue, Feb 10, 2009 at 1:15 PM, Igor Pirnovar wrote: > Rick Denatale wrote: > > On Tue, Feb 10, 2009 at 3:19 AM, William James wrote: > > > > As 7Stud pointed out, a toolbox with only regular expressions > > inside is often a poor choice for dealing with xml/html > > > > Here's a rather verbose and commented program using a > > combination of hpricot and a regular expression to do > > something like what I think you are looking for: > > > > require 'rubygems' > > require 'hpricot' > > . . . > > > > When run this outputs: ["123313"] > > > > In other words it produces an array of strings representing > > the target numbers in a script tag within a td tag which > > follows another td tag whose inner text is "Traffic left:" > > Rick, your solution is swell, and it is probably worth while considering > by someone whose day job is parsing html/xml documents. However, purely > from a language and/or from a programmer's perspective William's > solution is far more appealing, subjective. > much shorter, certainly, particularly with my pedagogical comments, easier to understand and I'd be quite willing to argue that. > > requires virtually no additional learning effort. Yes, we wouldn't want to expend any unnecessary effort on learning would we. And by the way to get that to work (in Ruby 1.8) a nuby rubyist would have to learn that you'd need to include 'enumerable' to get the cons method. > It nullifies or > "flattens" the comment started out by 7Stud that you also elevated to an > undeserving height. > You can treat regular expressions as a Maslovian hammer, but I've had enough experiences with xml to realize that that hammer is often a very poor tool for parsing html. I'd rather expend my learning budget in learning how to apply a tool like Hpricot than to debug my own low-level attempts. But, as they say, to each his own. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale --00163630f0ef23c6420462977024--