From: James Edward Gray II Date: 2006-03-08T23:01:13+09:00 Subject: Re: Is there link extractor or similar html processing libs for Ruby On Mar 7, 2006, at 7:48 PM, William James wrote: > class String > def xtag(s) > result = [] > scan( %r! > < #{s} (?: \s+ ( [^>]* ) )? / > > | > < #{s} (?: \s+ ( [^>]* ) )? > > ( .*? ) > !mix ) \ > { |unpaired, attr, data| h = { } > ( unpaired || attr || "" ). > scan( %r{ ( \w+ ) \s* = \s* > (?: ( ["'] ) ( .*? ) \2 | ( \S+ ) ) > }x ) { |k,q,v,v2| > h[k.downcase] = (v || v2) } > block_given? ? ( yield [ h, data ] ) : result << [ h, data ] > } > result > end > end > > DATA.read.xtag('a'){|atr,txt| puts atr['href'], txt } > > __END__ > href = "alert('Junior broke it!')" >foo bar > href = www.foo.bar >foo bar > > upcoming HTML 3.2 reference. All the > is A, with the attribute HREF. > Help | Javascript Link James Edward Gray II