From: Dave Hoefler Date: 2007-02-13T07:08:26+09:00 Subject: Re: What's the best way of parsing this string? ------=_Part_60492_5823230.1171318097266 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Jason, Thanks for the suggestion. Why would REXML be a good use though? -Dave On 2/12/07, Jason Roelofs wrote: > > 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) > / Regexps can help you out if it comes to this. > > Jason > > On 2/12/07, Dave Hoefler 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_60492_5823230.1171318097266--