From: Jason Roelofs Date: 2007-02-13T06:49:37+09:00 Subject: Re: What's the best way of parsing this string? ------=_Part_32616_2093869.1171316970567 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Well, maybe you can assume valid XML and parse the page with REXML. If it's not valid XML, well you can regex through for (off-the-cuff, probably wrong) / wrote: > > Hi there, > > I have a question about string search and replacement. Let's say I have > this > string that contains 2 links for embedding youtube videos amongst > some other random text. > > string = "We've got some junk text here" + > " value=\"http://www.youtube.com/v/qqsyXdj_p_I\">" + > " src=\" > http://www.youtube.com/v/qqsyXdj_p_I\" > type=\"application/x-shockwave-flash\"" + > "wmode=\"transparent\" width=\"425\" > height=\"350\">" + > "And we've got some more junk text right here" + > " value=\"http://www.youtube.com/v/yYqACgndOQA\">" + > " src=\" > http://www.youtube.com/v/yYqACgndOQA\" > type=\"application/x-shockwave-flash\"" + > "wmode=\"transparent\" width=\"425\" > height=\"350\">" + > "more garbage text here" > > I'd like to get the value of the 'value' attributes (" > http://www.youtube.com/v/qqsyXdj_p_I" and " > http://www.youtube.com/v/yYqACgndOQA" respectively) and convert the string > into the following: > > We've got some junk text here >
> > And we've got some more junk text right here >
> > more garbage text here > > > What would be the best library to use for parsing and replacing certain > values in a string? I've done simple .gsub'ing before, but this seems to > be > a little more complicated ;-) > > Thanks, > Dave Hoefler > ------=_Part_32616_2093869.1171316970567--