[Ruby] regex question

Daevid Vincent daevid at daevid.com
Mon Feb 12 16:50:41 PST 2007


I know this is a radical idea, but you could just parse the XML into a DOM
as God intended it to be, and then delete the nodes in the DOM and re-save
it out...

I suspect any regex is going to have some gotchas with a sufficiently large
data-set and cause you to delete something you didn't intend to, or miss
something you wanted to catch.

;-)

DÆVID  

> -----Original Message-----
> From: ruby-bounces at zenspider.com 
> [mailto:ruby-bounces at zenspider.com] On Behalf Of Aaron Patterson
> Sent: Monday, February 12, 2007 4:41 PM
> To: Seattle Ruby Brigade!
> Subject: Re: [Ruby] regex question
> 
> On Mon, Feb 12, 2007 at 03:52:45PM -0800, shaners becker wrote:
> [snip]
> > i'm trying to rip out all of the recommendations, so i'm left with  
> > just my books in my library, not the ones i might want in 
> my library.
> > 
> > so... i tried both:
> > 
> > 
> > /<recommendations>[^<]*<\/recommendations>/
> > /<recommendations>.*?<\/recommendations >/
> > 
> > neither of them found any results.
> 
> When  you say "any character" in a regular expression, it 
> actually means
> any character except for newline.  If you've got newlines in 
> there, add
> the 'm' flag:
> 
>   foo.gsub(/<books>[^<]*<\/books>/m, '')
> 
> I'm not sure how you'd do that in textmate....
> 
> -- 
> Aaron Patterson
> http://tenderlovemaking.com/
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
> 



More information about the Ruby mailing list