From: James Coglan Date: 2009-03-28T19:22:06+09:00 Subject: Re: Regular Expression interesting problem --001636c5a81c6bb62504662b3806 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 2009/3/28 Arun Kumar > Eric Hodel wrote: > > On Mar 28, 2009, at 02:07, Arun Kumar wrote: > >> /> > >> interesting problem, but i need help for solving it. Please help me. > > I suggest you use Nokogiri. > > > > Barring that, don't use regular expressions, use something more > > appropriate like StringScanner from strscan.rb. `ri StringScanner` > > will get you started. > > > Nokogiri is a good option. But i want to use net/http for my assignment > and it is compulsory. > > > PS: You'll probably want to do something like scan for <, then scan > > for a tag name, then scan for attributes, then scan for >, etc. > > As you said I have to check the tag ie' the attributes. But still the position of the type attribute is the > problem. Looks like you will need to parse in stages -- I can't get String#scan to capture everything using a single regex, though there's every chance I've screwed up the expression somehow: ''.scan /<([^\s]+)(?:\s+([^\s]+)="([^"]*)")*\s*\/?>/i #=> [['link', 'rel', 'alternate']] --001636c5a81c6bb62504662b3806--