From: Eric Hodel Date: 2009-03-28T19:00:49+09:00 Subject: Re: Regular Expression interesting problem On Mar 28, 2009, at 02:07, Arun Kumar wrote: > Hi, > I'm learning about regular expressions right now for a html scraping > based assignment. But now I've reached a problem. Given below are two > different html tags. > > href="http://newsrss.bbc.co.uk/rss/newsonline_world_edition/help/rss/rss.xml > " > rel="alternate" type="application/rss+xml" title="BBC NEWS | Help | > RSS" > /> > > href="http://gdata.youtube.com/feeds/base/standardfeeds/top_favorites?client=ytapi-youtube-index&time=today&v=2 > "> > > Now what i want is to capture the href-url if the type = > "application/rss+xml". It seems to be simple but it is the position of > the 'type' that creates the problem. In first tag the 'type' is after > href and in the second the 'type' is before it. It seems to me as an > 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. 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. PPS: There's no need to post twice.