From: Caleb Clausen Date: 2008-09-08T23:29:56+09:00 Subject: Re: regular expression match and exclude On 9/7/08, Azalar --- wrote: > I am parsing a web page full of image links that also contain links to > the thumbnails for those images. > > Here is my test data.. > > galleries/image1.jpg > galleries/image1thumb.jpg > galleries/image2.jpg > galleries/image2thumb.jpg > galleries/image3.jpg > galleries/image3thumb.jpg > > If i use this expression.. > /galleries.*(?=thumb).*jpg/ > > The results are just those lines containing the word thumb. > > What I want to do is inverse this though and return only return that > DONT contain the word thumb. Using Reg, my DSL for declarative programming in ruby, you can use the logical operators (& | ~) to combine regexps. I call this 'match arithmetic'. The resulting objects implement === and =~, so they can be used with Array#grep. require 'rubygems' require 'reg' images=["galleries/foo.jpg", "galleries/foothumb.jpg"] images.grep /galleries\/.*\.jpg$/ & ~/thumb\.jpg$/ #in galleries and not thumb There might well be a pure regexp way, but I've been unable to come up with a clean one....