[Ruby] regex question

Aaron Patterson aaron_patterson at speakeasy.net
Mon Feb 12 16:41:20 PST 2007


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/


More information about the Ruby mailing list