From: Robert Klemme Date: 2008-09-09T00:04:20+09:00 Subject: Re: regular expression match and exclude 2008/9/8 Caleb Clausen : > On 9/7/08, Peņa, Botp wrote: >> irb(main):036:0> re2 >> => /galleries.*?([^t][^h][^u][^m][^b]).jpg/ >> irb(main):038:0> g.select{|x| x=~re2 } >> => ["galleries/image1.jpg", "galleries/image2.jpg", "galleries/image3.jpg"] > > Unfortunately this way will fail to match (for instance) "bomb.jpg". > If you want to go this route, you need to do something like this: > (untested!) > > /^galleries.*([^t]humb|[^h]umb|[^u]mb|[^m]b|[^b])\.jpg$/ #bleah > > Patrick He wrote: >> /^galleries\/((?!thumb).)+\.jpg$/ > > Ah, brilliant! But it doesn't quite work. It fails to match > "thumb_foo.jpg", which probably should match here. A simple > modification should fix it, tho: > > /^galleries\/((?!thumb\.jpg$).)+\.jpg$/ > > There. That's a pretty nice pure regexp. Now just make the group non capturing and you're a tad more efficient. :-) %r{\Agalleries/(?:(?!thumb\.jpg\z).)+\.jpg\z} Cheers robert -- use.inject do |as, often| as.you_can - without end